Adding Gravity in Unity
Make the player be attracted to the floor.
Objective: add gravity to the game through script.
We have a player able to move but he is static in the Y axis and that is not the behavior we want. In this case we are going to add gravity through scripting.
In the player script I created a new variable for the gravity value. Then in the update method now I check if the player is grounded, if it is false so we are going to apply the gravity by subtracting the value of the gravity variable to the velocity vector in the Y axis.
And that’s it!!! Now the player starts falling when is not grounded.