Question by
Reactorcore3 · Jul 24, 2020 at 07:34 PM ·
gravityphysics2d
Detect / Get Gravity value?
I want to have a 2D platforming character detect if the environment is zero gravity or normal gravity so they know when to change movement modes but I can't find a Get Gravity 2D function anywhere.
How do I get the value of gravity from the current gravity settings?
Comment
Best Answer
Answer by Reactorcore3 · Jul 24, 2020 at 08:47 PM
Turns out its as easy as: (3D games)
public Vector3 storeVector
public override void OnUpdate()
{
DoGetGravity();
}
void DoGetGravity()
{
Vector3 gravity = Physics.gravity;
storeVector.Value = gravity;
}
Or (2D games)
public Vector2 storeVector
public override void OnUpdate()
{
DoGetGravity();
}
void DoGetGravity()
{
Vector2 gravity = Physics2D.gravity;
storeVector.Value = gravity;
}
Your answer
Follow this Question
Related Questions
Projectile in angry birds not working as expected 3 Answers
How to Set Gravity for large sprites ? 0 Answers
Ball is not falling 0 Answers
Uneven Jump Heights 1 Answer
Why is my momentum not carrying over to the X axis? 0 Answers