0 votes

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.play("right_attack")

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

in Engine by (12 points)

1 Answer

0 votes

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!

by (47 points)
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.
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 webmaster@godotengine.org with your username.