need some insight about subtracting velocity as fall damage

Hello,
I wanted to make a simple fall damage check.
But becouse i am learning python i dont fully understand how i can get this done.
what i got so far:


speed = Object.getLinearVelocity()[2]  
    if speed < -5 and speed > -10: //so if speed is between -5 and -10
        Object['Health'] -= 5  //subtract health, but this gets kinda repeated a few times while i just want it to subtract it once
        print (speed)  

My question would be, how can i make it so it only subtract once when hit the ground.
i have also added an “and Groundcheck.positive” but then the script wont work at all (yes Groundcheck exists).

all i want is if it hits the ground that it subtract the damage.
it would even be better if the speed could be directly substracted to reduce the script size, but thats not the main thing that i want, i just want it to work

Is there an easy way to fix this?
Thanks allot.

if it gets subtracted several times, the code is executed more than once. so the problem lies with the sensor or call that makes the code execute

Use a timer, when you hit the ground assign time = 0, if time = 0.1 then health -= 5.

Have a look at the collision demo

I have tried it in a few ways but didnt work as i wanted it to work.

What i wanted is to grab the last fall speed and subtract it from the hp when hitting an object.

I however have solved it by using a ray at -z direction with a range of 0.500 and putted it on TAP mode.
now it ectracts the actual falling speed from the players hp.

the script now:


FallCheck   = Controller.sensors['FallCheck'] //the ray
speed = Object.getLinearVelocity()[2]  
    if FallCheck.positive and speed < -7: # -7 as the minimum to activate
            Object['Health'] += speed # speed returns a negative number (-z axis) so u need to + it in order to subtract it.

i use this very simple thing, you need to be aware anyway for example that the jump is < of the velocity that give damage.

so avoid unnatural big jump.


if not "init" in own:
    own["init"] = 1
    own["oldVel"] = own.worldLinearVelocity.copy()


#blah blah.. code

#and at the end more or less

impact = (own["oldVel"] - own.worldLinearVelocity).magnitude
if impact &gt; 15 : #be aware to choose well this 
    own["energy"] -= 0.7

own["oldVel"] = own.worldLinearVelocity.copy() # refresh the velocity to store for the next frame! 

so avoid unnatural big jump.
What do u mean?

the damage is calculate with the differencial between the previous and the new verlocity , example:
old +500
new 1
500-1 = 499 -> a big boom.

the jump in a game is done usually as a unnatural(without pre-charge) change of velocity (ex to 0 to 10 in one frame)
this can be read as impact (in fact is a impact)