Game Development Reference
In-Depth Information
In order to simulate physics on many bodies in real time, there are many different
optimizations and simplifications. Let's cover some of them:
All movements, just like in real life, are handled by impulses and forces.
The impulse is applied instantaneously; for example, if a moving ball
collides with a standing ball, the standing ball gets an impulse in one
moment. Force is a continuous effect that moves the body in some direction.
For example, launching a rocket is slow and steady as force gets applied
that pushes it up. All forces and impulses add to each other; thus, you can
have very complex movements with little hassle.
All bodies are considered rigid—they can't deform as a result of physics
simulation. Of course, you can write your system over existing physics
simulation to do that for you, but it is not provided out of the box.
Each physics body has many properties, some of which are as follows:
Mass : This is the mass of the body in kilograms. The more massive the body
is, the harder it is to move by impulses or forces.
Density : This indicates how much mass the body has in a fixed amount of
volume. The denser the body is, the more mass it has for the same volume.
Dynamic : This is the property that allows you to apply impulses or forces
to the body. Sometimes it is not needed; for example, ground will always be
static and not dynamic. You might also pick dynamic if you want to move
your body yourself, without the physics engine touching it.
Restitution : This is the property that determines how "jumpy" or "bouncy"
the body is. The higher this is, the higher the knockback is. This ranges
from 0 to 1, but you can set this higher than 1, and in this case, the body will
accelerate each time after the collision, which may eventually lead to a crash.
usesPreciseCollisionDetection : This is used to handle very fast moving
objects. There are certain situations in which collision might not get detected,
for example, if in one frame, the body is in front of another body, and in
the next frame it is completely behind it without touching it; in this case,
the collision will never be detected, and you don't want this. This method
is very CPU-intensive, so use it only if absolutely necessary.
affectedByGravity : This property is set to NO if you don't want some objects
such as balloons to be affected by gravity.
categoryBitMask : This is the bitmask that identifies the body. You might
choose different bitmasks for different objects.
 
Search WWH ::




Custom Search