Game Development Reference
In-Depth Information
Falling to your doom!
The first thing that we need to do is give our player a collider. For this game, we don't
need to be too concerned about the player's specific shape; so for that reason, we can
use a box collider . We don't want to use a circle or polygon collider here because it
would result in the player just sliding off the platform. A box collider gives a nice,
flat surface for the physics to collide with. A box collider is also the quickest type of
collider to use for performance. Select the Player object and attach a Box Collider 2D
component to it, which is found under Component | Physics 2D in the menu bar. The
collision box on your player should look like the box in the following screenshot:
Now that the player has collision information, let's give it some actual physics.
Attach a Rigidbody 2D component to the player. A Rigidbody component is sort
of what it sounds like—a physical body that is completely rigid, as opposed to a
Softbody component that would be used for things such as cloth, rubber, and hair.
With the Rigidbody 2D component attached, change its Gravity Scale property to 2 .
This scales the gravity to something a bit higher so that the player can fall in a more
realistic manner. If you play with the gravity scale setting, you can see how different
types of objects would have different gravity scales—it allows heavy objects to fall
quickly, and very light objects to fall slowly (or even rise)!
Also, set the Sleeping Mode property to Start Awake and the Collision Detection
property to Continuous . We want this to be continuous because the player is
constantly moving and in control; therefore, we need the player to always be
carefully checking its collisions. If you were to set it to something other than
Continuous , there is a higher chance of the physical collisions not registering,
causing the player object to pass through other colliders.
 
Search WWH ::




Custom Search