- Home /
How Do I Increase Gravity Overtime If My Player Stays In The Air Longer?
I'd like more gravity to be applied to my player if he is not grounded overtime, how can I do that? Im pretty new to Unity so don't mind me :)
The question is about increasing gravity over time. Default gravity is constant.
Answer by FlaSh-G · Aug 17, 2020 at 06:27 PM
It's hard to give any specifics without you providing any code, but the basic idea would be to have a value that gets set to the default gravity in each FixedUpdate you are grounded, and increase the value by a set amount each FixedUpdate while not grounded. Then, apply that value as the gravity for the player.
If you were using a Rigidbody2D, you could simply use the component's builtin gravity scale:
public float defaultGravity = 1f;
public float gravityIncreasePerSecond = 0.2f;
private void FixedUpdate()
{
if (grounded)
{
rigibbody2D.gravityScale = defaultGravity;
}
else
{
rigibbody2D.gravityScale += gravityIncreasePerSecond * Time.deltaTime;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613005835im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody--Addforce on a Spherical Platform(A Globe) 2 Answers
How do I slow down while Im Sliding? 0 Answers
Slime script? 1 Answer
How do I build up speed while wallrunning? 1 Answer
Moving a object up 1 Answer