+1 vote

I have a player and a few enemies. When the player shoots and the bullet collides with the enemy, I want to play a hit animation on the enemy.

Simplified code:

func _on_shot_body_enter(body):
    print("shot enemy", body)
    body.hp=body.hp-1
    body.get_node("body/anim").play("hit")

The collision part works, and the individual hit points work. However; ALL of the enemy instances play the hit animation, not the specific individual instance that was hit. In the Output I get: shot enemy[KinematicBody2D:605]

I tried a few different tactics, even using a hit function and calling

self.get_child(0).get_child(0).play("hit")

but still have all enemies trigger. I suspect it is because of the get_node part, but I am not sure how to trigger only the instance hit's AnimationPlayer.

asked May 10, 2016 in Engine by nokungfu (29 points)

That's weird, the code you posted should work fine to trigger the animation of the specific enemy instance that was hit, and not of the other instances.

How did you setup your scene tree?

Thanks Akien,

I started adjusting hierarchy of things, but was still having the same result, so I turned to the animation and found my mistake:

When playing the hit animation, instead of keyframing the sprite's Texture property (.:texture), I keyframed the sprite's ImageTexture property (.:texture:image).

face palm.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.