Managing player movement
When you're deciding on how best to move your player character around your virtual world, consider what's going to look the most realistic and not run your game into the ground with expensive computations. This is somewhat of a trade-off in most cases, and Unity is no different.
The three most common ways of moving a GameObject
and their results are as follows:
- Option A: Use a
GameObject
'sTransform
component for movement and rotation. This is the easiest solution and the one we'll be working with first. - Option B: Use real-world physics by attaching a Rigidbody component to a
GameObject
and apply force in code.Rigidbody
components add simulated real-world physics to anyGameObject
they are attached to. This solution relies on Unity's physics system to do the heavy lifting, delivering a far more realistic effect. We'll update our code to use this approach later on in this chapter to get a feel for both methods...