A really snappy Unity player controller.
To use this player controller for your own game you have to follow these steps.
Let's first add all the necessary components to the player object.
- First you have to add the
"PlayerController.cs"script to your player game object. - Next you have to add a
"Rigidbody"component to your player. - Now you have to add a collider to your player.
- Now drag the
"Rigidbody"component to the"Rigid Body"field on the"PlayerController"component.
Now lets add the input methods.
You need to add inputs called Horizontal, Jump and Fall.
To get to the inputs menu, you have to go to Edit > Project Settings > Input in the menu bar.
| Input Name | Positive Button | Negative Button |
|---|---|---|
| Horizontal | The right button | The left button |
| Jump | Jump Button | |
| Fall | Fast-Fall Button |
Add the tag "Ground" to your ground object.
These are the last steps to do if you want to recreate the example.
The player object has to be a 3x3x1 sphere with a y position of -8.45.
Change the mass under the "Rigidbody" component to 1.5 and freeze the Z rotation.
Click on Edit > Project Settings > Physics in the menu bar.
Change the "Gravity" to
| X | Y | Z |
|---|---|---|
| 0 | -58.86 | 0 |
Make a cube with the following "Transform"
| X | Y | Z | |
|---|---|---|---|
| Position | 0 | -20 | 0 |
| Rotation | 0 | 0 | 0 |
| Scale | 50 | 20 | 10 |
Change the background color to HEX 428BFF.
Change the "Transform"
| X | Y | Z | |
|---|---|---|---|
| Position | 0 | -0 | -45.23 |
| Rotation | 0 | 0 | 0 |
| Scale | 1 | 1 | 1 |