Game Development Reference
In-Depth Information
Controlling the hero
A sprite that only stands on the screen isn't going to make much of a game, so we'll add a
script to allow the player to move the hero to the left or right.
First, we'll add the physics of the movements related to our hero; we don't need anything
heavy, just a ridged body so that we won't pass through other objects in the world and a
collider so that we know when we bump into things:
1. Add a RidgedBody2D component by navigating to Add Component | Physic-
s2D | RidgedBody2D in the player's GameObject inspector.
2. Set the Gravity Scale parameter to 0 (as we are not using gravity), and check the
Fixed Angle checkbox (as we want the player to always remain in the standing
position).
3. Next, add a BoxCollider2D component by navigating to Add Component |
Physics2D | BoxCollider2D , and scale down the Size X parameter to 0.36 (just
to narrow the collision box to the width of the hero).
This should give you the view as shown in the following screenshot:
Search WWH ::




Custom Search