Change sprite when hit by raycast

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tato64

Hello wonderful members of the community!

Long story short:
I shoot an enemy (my projectile is a raycast), i want his sprite to change accordingly.

Im using animatedsprite to handle character sprites, relevant code is the following:

if hasgun and Input.is_action_just_pressed("lclick"):
	if $Pistol/RayCast2D.get_collider().is_in_group("enemy"):
		print($Pistol/RayCast2D.get_collider().name) #just for debugging

But this is not working.

(“Body” in the last line is the name of the AnimationPlayer)

:bust_in_silhouette: Reply From: exuin

Try $Pistol/RayCast2D.get_collider().get_node("Body").play("dead") instead?

.Body just gets the property named Body from the collider, which isn’t what you want.