Moving the player with a player controller script
We’ll need more than just input to move our player character around the level. We’ll have to configure the Player
object to work with the Physics system so that it interacts with our level’s ground and platforms and interactivity trigger volumes, and then applies the movement force.
Configure the Player
Prefab’s root GameObject with the following components while referring to Figure 5.11:
- Add a
Rigidbody2D
component (by pressing the Add Component button) with these values:- Use Auto Mass enabled: Physics objects react more believably in the physics simulation if they have proper mass. This setting will estimate the mass based on the density and area of the accompanying collider.
- Linear Drag =
1
: We’ll add some drag to the player’s movement to provide additional constraints on the move to help the player feel more grounded and not very floaty. - Constraints | Freeze Rotation Z enabled: We...