How can i make the Player Sprite change if it's near an enemy?

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

So far i did this:
Created Area2D on Player, added CollisionShape2D to it
enter image description here
Connected that Area2D using body_entered signal to Player

(I added the enemy to the group Enemies to make things easier i hope it’s not ruining anything)
Stuff looks like this:

func _on_EnemyDetector_body_entered(body):
if body.is_in_group("Enemies"):

AnimatedSprite has right_attack assigned, i have things set up properly i believe.
At least when my character moves it changes sprites depending on the direction.

Yet i can’t make the Player sprite change when Area2D assigned to him “encounters” the Enemy. Would appreciate any ideas.

enter image description here

:bust_in_silhouette: Reply From: Aravash

Are you sure the enemy is on a layer that the player’s collision shape is looking for?

in project>project settings>2d physics there is a list of names you can give to bit masks and layers.

you can then assign these to colliders in the scene by opening the collision tab on the collider’s parent node. A collider only registers collisions with objects whose masks they are specifically ticked to look for. Simply, a Layer is what it is, a Mask is what it collides with.

If nothing still happens, try using print("output text") to see if your function is even called at all. If it is called, then it’s an issue with playing the animated sprite, if it isn’t called, it’s probably an issue with the above.

Best of luck!