Topic was automatically imported from the old Question2Answer platform.
Asked By
GodotUser21
I am trying to make my character die from fall damage. So I use this code
velocity.y += gravity * delta
fall_strength += 1
But there is one big issue. It is that as long as I am not on the floor, I take damage. I was thinking of storing the y position of the player in a variable after a jump was made and subtracting the y position after the character hits the floor. (the y position will be stored in another variable when the character hits the floor)
Since I just started with Godot, I do not know how to do this.
Also, another concern is with the negative numbers since if my character drops from a negative number, e.g. drop from y = -145 and lands on a negative number when hits the floor, e.g. y = -230, it will give me a positive number. And when my character drops from a positive number, e.g. y = 500, and lands on the ground that is a positive number, e.g. 100, means I cannot put a fixed height limit that my character can fall
You should be able to just use the velocity.y to determine if the player should take fall damage rather than storing an extra fall_strength variable and distance fallen. velocity.y will constantly increase based on your gravity.
if velocity.y is positive it means your player is falling, if it’s above a particular threshold then you can apply fall damage, you could also set different thresholds of instant death vs damage.
Does this work for a kinematic body 2d???
GodotUser21 | 2022-09-08 09:10
Yes, you don’t have to do the full state system in the video.
Have you got the code that detects when the player lands on the ground?
share your full code for func _physics_process(delta): if you like and I can give better advise.
petermoyle | 2022-09-08 09:27
Edited this response as i got my positive and negative mixed up, velocity.y will be a positive number when falling.