I have gravity on my player but its not working
Here is my code:
void Update ()
{
moveDirection.y -= falling.accelerationDueToGravity * falling.playerMass * Time.deltaTime;
moveDirection.y = Mathf.Max (velocity.y, -falling.terminalVelocity);
playerController.Move (moveDirection * Time.deltaTime);
}
Those variables are in classes, that’s why i have things like falling.acceleration.
When I play, the gravity is not working, please help.
Thanks in advance.
If you want your object (e.g. a player) to fall due to gravity, you need to attach rigidbody and mesh components to the gameobject.
To change gravity’s value through scripting Physics.gravity = Vector3(0, -9.8f, 0);
or go to Edit>Project Settings>Physics
http://docs.unity3d.com/ScriptReference/Physics-gravity.html
Hi sorry for wasting your time i made a stupid mistake. Thanks nonetheless for the help.
Here is the working code:
void Update ()
{
velocity = playerController.velocity;
moveDirection.y -= falling.accelerationDueToGravity * falling.playerMass * Time.deltaTime;
moveDirection.y = Mathf.Max (moveDirection.y, -falling.terminalVelocity);
playerController.Move (moveDirection * Time.deltaTime);
}