Hi Nukem,
First of all, you have to define what you mean by “falling” because we must not forget that Unity’s physics simulation is also working on our player.
The problem with Rick’s code is that we manipulate the transform.position
directly. We override the values that were applied by the physics simulation.
The “correct” way to move a game object within the physics simulation is to use the Rigidbody and call, for example, AddRelativeForce on it. Since I understood that you would like to challenge yourself, you could look that method up in the Unity API, and try to implement it in your game. It’s not difficult.
In the Project Boost game, Rick uses the AddRelativeForce method to make his rocket fly.
If you just want to make your player fly and ignore the “physics”, your idea is the way to go. Maybe rename the “Jump” axis to “Fly” in the Unity Settings, and rename it accordingly in your code, so when you read your code in a few weeks, you immediately understand what it is supposed to do.
Whether you have to make custom keys depends on your idea. For example, if you want to use the spacebar for the “flying”, you could check against that value via Input.GetKey. You don’t have to implement a new “axis” in the Unity Settings.
Did this help?
See also: