Knowing when to use physics
The most obvious method to improve the performance of a feature is to avoid using it as much as possible. For all movable objects in our game, we should take a moment to ask ourselves if getting the physics engine involved is even necessary. If not, we should look for opportunities to replace them with something simpler and less costly.
Perhaps we're using physics to detect whether the player fell into a kill-zone (water, lava, a death-plummet, and so on), but our game is simple enough that we only have kill-zones at a specific height. In this case, we could avoid physics colliders altogether and get away with only checking whether the player's y-position falls below a particular value.
Consider the following example—we're ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access