The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+3 votes

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)

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


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.

in Engine by (33 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.