I’m using a very basic script for climbing a ladder (see below), which switches off gravity and allows my player to climb up or down.
When the player exits the ladder (using OnTriggerExit2D), their gravity is returned to normal (in this case, a value of 10) using body.gravityScale = 10f;
.
I would prefer this to return the player’s gravity to its ‘default’ value - as in, whatever it is is set as in the inspector. How can I reference that value here, instead of saying = 10f;
? This seems like it should be simple, but I can’t find it anywhere/figure it out myself!
Thanks for your help.
private void FixedUpdate()
{
if (isClimbing)
{
body.gravityScale = 0;
body.velocity = new Vector2(body.velocity.x, vertical * speed);
}
else
{
body.gravityScale = 10f;
}
}