Game Development Reference
In-Depth Information
How it works...
The createSegment method creates a new bridge segment that is sphere shaped, both
in physicsSpace and the visible world. This is the part that has a mass and can be se-
lected by clicking on it, since Ray only collides with spatials.
The createJoint method creates the visible connection between the newly created seg-
ment, and the currently selected one. It does this using Point2PointJoin t. This is dif-
ferent from, for example, HingeJoint , since it's not fixed in space, when several
Point2Pointjoints are connected and you have something that resembles a bridge.
The mouse selection is covered more in depth in other chapters, but it works by shooting
Ray from the mouse's position on the screen, inwards into the game world. Once Ray hits
Geometry (which has BoundingSphere that is slightly larger than the visible mesh for
increased selectability), the corresponding RigidBodyControl will be selected.
There's no challenge in a bridge-building game if the segments don't have a maximum
force they can handle before they break. This is what we take care of in the update meth-
od where we check appliedImpulse on each segment. If it goes above a certain
threshold, it can be considered to be overloaded and removed, often with disastrous results.
We also set linearVelocity along the z axis on each segment to 0 since it's a 2D game
and we don't want anything to move to the depth layer.
We start the game with the physics simulation off by setting the speed of bulletAp-
pState to 0 . Without doing so, building the game will get tricky pretty fast as everything
will fall down. Pressing the Space bar will start the physics, and let the player know wheth-
er their engineering skills are up to par.
Search WWH ::




Custom Search