This lesson teaches you how to interact with physics in a scene.
Playing the GameRun the project. The first challenge is getting up on a ledge, we can achieve this by picking up crates. When we move close to the crates the hand icon will appear. We can pick our crate up now by pressing E
Drop the crate by pressing E again. If you want to throw the object away, press the left mouse button. When you drop a crate to the floor or when the crate hits a wall, it will make a random sound. If you look around to fast you will lose grip and the crate will drop.
Another useful features is that when a picked up object gets stuck behind a wall or gets stuck on a wall, the player will drop the object automatically when the distance between the object and the player gets to large.
We stack up the crates so that we can get on top of the ledge.
Next we will encounter the classic "seesaw" puzzle. When we walk on to the seesaw on order to reach the second ledge, you notice that the player will will cause the seesaw to rotate. We can prevent this from happening by stacking cinder blocks on one side of the plank.
When we have placed enough blocks, we can walk to the other end of the plank without the plank rotating. We can now safely reach the second ledge.
The CratesThe FPSPlayer prefab has build in pickup functionality. In order for objects to be picked up we can have a look at the crates. Select a crate and go to the collision tab. The collision is set to rigid body, the mass is set to '2' and the collision type is set to 'Prop'.
The impactnoise script is attached to all crates. This scripts allows you to specify several 'impact sounds' that are played randomly when an object hits the floor. The threshhold value determines the minimum speed iin order for a collision to make a sound. The sound range determines what the maximum range is for the sound to be heard.
The SeesawThe plank has the hinge.lua script attached. This script creates a joint hinge on the specified axis. If we set a 1 on the Z field we say that the joint should be placed on the Z axis. The Z axis is the blue arrow of the position gizmo. See the image below.
The limits determine the maximum rotation angles of the joing hinge. With the seesaw this prevents the plank from rotating in to the ground.