Time for action – adding a Rigidbody to the Player
We're going to add a Rigidbody
Component to apply physics to Player. To stop Player from dropping like a rock, out of view of the camera, we'll check Is Kinematic in the Rigidbody properties to turn off the effect of physics. When any of the play States are active, we'll uncheck Is Kinematic in code to allow physics to affect Player.
- Select Player in the Hierarchy panel.
- At the bottom of the Inspector panel,navigate to Add Component | Physics | Rigidbody.
- In the Rigidbody Component, check Is Kinematic.
The following screenshot shows the code for moving Player using physics forces:
What just happened? ...
Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.