Game Development Reference
In-Depth Information
This time the cube retains its position but spins wildly when the other cubes collide with it. You will
see the Rigidbody constraints used in 3D-platform, jumper-type games where the objects may only
move in the Y or Z directions and rotate on the X axis. This serves to keep them on the ramps and
platforms without using invisible collider walls.
Forces
A less passive means of affecting objects with Rigidbody components is by using a physics Force.
Through scripting, you will be able to add a one-time force for objects such as projectiles. The
component force, Constant Force, is constant or, more accurately, continuous.
1.
Select the middle cube.
2.
From the Component menu, Physics, select Constant Force.
3.
Give it a Z force of 10 (or -10 if you wish) to send it off over the hills.
4.
Zoom out a bit in the Scene view.
5.
Click Play.
The cube goes rolling off over the terrain until it falls in a hole or goes off the edge of the terrain.
Adding a local or Relative force to the bouncy cube will send it off.
1.
Stop Play mode.
2.
Add a Constant Force component to the top cube.
3.
Set its Relative Force, Y to -2 .
4.
Click Play.
The initial downward force causes the cube to bounce more violently, causing it to spin. The force,
being local, causes the cube to go off in unexpected directions.
While Force is a linear motion, Torque causes rotation.
1.
Stop Play mode, and select the bottom cube.
2.
In the Rigidbody Constraints, activate its X and Z Freeze Rotation
parameters.
3.
Add a Constant Force component to it.
4.
Set its Torque, Y to 1 .
5.
Click Play.
This time the cube is rotating before the other two interact with it.
6.
Stop Play mode.
7.
At the top of the Inspector, deactivate the top and middle cubes.
8.
Click Play.
 
Search WWH ::




Custom Search