Game Development Reference
In-Depth Information
How it works...
Running the result, we should see the stickman desperately trying to stay upright while
flailing his arms up and down. The reason is that getting the forces right when balancing
can be very difficult. With values that are too high, the stickman will constantly overshoot
the target and instead rotate in the other direction. With values that are too low, it won't
have the strength to get upright. With some further tweaking to targetVelocity and
maxMotorForce , we might be able make him stable.
We started by creating the basic shape of a figure that would try to keep the balance. The
waist was made to not be affected by the physics, so it could be a solid point. We then ad-
ded a torso and two arms, resulting in a center of mass somewhere in the upper part of the
torso. By placing each of the body parts at some distance from each other with the joints,
we give them more freedom of movement.
The BalanceControl class we created has one simple strategy. It looks for the torso
(bodyA)'s rotation along the x axis, and tries to keep it as close to 0 as possible. If it notices
that it's anything but near 0, it will try to move the arms, shifting the center of the mass to
the opposite direction.
Despite the low number of components, getting it all to balance out is really difficult! Hav-
ing more components, such as a whole human skeleton, requires a much more advanced
strategy, with body parts moving in a synchronized fashion, rather than they trying to do so
individually.
Search WWH ::




Custom Search