Jump to content

* * * * *
Contents


This lesson teaches you how to interact with physics in a scene.

Attached Image: 1.PNG

Playing the Game

Run 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

Attached Image: 2.png

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.

Attached Image: 3.PNG

We stack up the crates so that we can get on top of the ledge.

Attached Image: 4.PNG

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.

Attached Image: 5.PNG

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.

Attached Image: 6.png

The Crates

The 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'.

Attached Image: 7.PNG

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.

Attached Image: 8.PNG

The Seesaw

The 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.

Attached Image: 9.PNG

The limits determine the maximum rotation angles of the joing hinge. With the seesaw this prevents the plank from rotating in to the ground.

Attached Image: 10.PNG


1 Comments

In regards to the seesaw, the Hinge.lua script creates a joint on a specific axis. I am guessing the joint is created at the pivot point of the object?

Just want some clarification on that.