Calculating fall damage based off current velocity

I’m making a side-scrolling platform game which uses a grappling hook and and also includes fall damage based off velocity. the key mechanic of the game is using the grappling hook to prevent you from taking damage but as it stands, it calculates damage based off peak velocity of the fall and not the current velocity when you actually land, meaning the character is dying despite landing safely on the ground. i’d be very grateful if someone could help me out on this!

I think this is a logic issue. From what I can tell the check goes like (in order):

  • If z velocity is less than or equal -2500 AND greater than -3000 then damange = 10
  • else if z velocity is less than -3001.0 and greater than -3500 then damage = 20
  • else if z velocity < -3501 then damage = 300.

I guess this is fine, but what it doesn’t account for is what if you’re z velocity is > -2500? If this happens (presumably because you’ve used a gravity hook) then the damage will never be set to 0. Worse still, if your last damage was set at 300 due to a large fall (or 10 due to a small small) and you’ve been walking for a while, your next fall your damage may remain at 300 (or whatever the last fall damage was) if you’ve never exceeded the -2500 barrier for damage to be re-calculated (for example if you’ve just had a very small fall or you used the hook to keep a slow descent which never breased the -2500 threshold)

So, the fix can be as simple as adding a new check that says if z veclocty is > -2500, damage = 0.

However, I’d suggest that as you only ever want the velocity at the point of impact, why not stop trying to cache damage values in the player tick (which causes issues like you’re experiencing) and instead just cache the player velocity on that frame. You can then calculate the damage on hit knowing what the velocity was immediatly before the impact.