Game Development Reference
In-Depth Information
Figure 7-3. Player character and the moving platform obstacle
Note that because of the way the script is written, you could delete another section of the Elevated
Track and put in another moving platform obstacle using this same script. Before you do that, read
onward for more obstacles!
Joints and the Pendulum Obstacle
A joint is merely a point at which two objects come together. Whereas parent-child relationships
also link two or more game objects with Transform, joints link two objects using physics. This is
another case of Unity offering you more than one solution to choose from when constructing your
game to get the precise behavior that you want.
Fixed Joint
A Fixed Joint is the simplest of the joints. It ties one game object's movement to another
game object's movement much like parenting, only through the use of the physics engine
instead of the parent-child Transform relationship. In the Hierarchy, create a Sphere game
object and give it a Transform position of (11.4, 20.3, 60) and a Transform scale of (11, 11, 11).
Rename it Pendulum Sphere. Remember that any game object first needs a Rigidbody
component to be recognized by the physics engine, so in the Inspector select Add
Component ➤ Physics ➤ Rigidbody. Set the Mass property to 20. Again in the Inspector,
select Add Component ➤ Physics ➤ Fixed Joint (Figure 7-4 ).
 
Search WWH ::




Custom Search