I'm humbly coming before you again with my old project, which needs a ton of work. I have a kinematicbody2D character, but I need it to, upon being damaged, make a little jump and back away from the damaging obstacle, enemy, or whatever. He won't jump or even turn red and transparent all the time at this rate. The object looking for the trap is in his feet at this moment, the same trigger that looks for the ground. However, I believe that because it already detects the ground, it sometimes ignores the Damage group and never calls the hurt function. Is there a way to give the character some physics, or do I have to completely redo the code for a rigidbody2D character?
The hurt code is not completely finished as I have to make the health bar yet- but here's what I have so far. It's the best I seem to get him to do, but it's not the best, either. When damaged, he currently freezes and doesn't get pushed back- so I removed the motion.y = whatever depending on the toggle for flip_h. Apparently, the traps group is for instant death- but the damage group is right below that if statement.
func _on_Player_body_entered(body):
if body.is_in_group("Traps"):
get_node("DrNitrogen").visible = false
get_node("DeathAnim").visible = true
get_node("DeathAnim").frame = 0
get_node("DeathAnim").play("death")
get_node("DeathSound").play()
is_dead = true
elif body.is_in_group("Damage"):
damaged = true
var number = rand_range(1, 3)
get_node("hurt" + str(int(number))).play()
get_node("DrNitrogen").modulate = Color(1,0,0,0.4)
get_node("Timer").start(1)
func _on_Timer_timeout():
get_node("DrNitrogen").modulate = Color(1,1,1,1)
damaged = false