Rolling when character hits the ground

Hey everyone,

Just wondering if anyone could help me create a system that makes my character roll when they hit the ground from a certain height. Trying to use raycast currently but I can’t seem to get it right. If anyone could help that would be great.

I’m looking for something similar to the Skill Roll from Mirror’s edge.

:slight_smile:

I’m assuming you already have a system to check for a grounded state; why not keep track of the distance fallen? As long as the character is not grounded and the y-velocity is negative, add the distance moved in y each frame (Rigidbody’s velocity.y * Time.deltaTime) to a counter variable. When the character lands, i.e. when they become grounded again, check the counter variable to see if it’s above a configurable threshold value. If so, trigger the roll logic. Reset the counter variable when the character is grounded, or when the y-velocity becomes 0 or positive.

Depending on how the physics in your project works, you could also just check the y-velocity at the moment the character lands. This won’t work if your character reaches terminal velocity more quickly than you want the roll to be usable.