0 votes

I am making a 2d isometric game and I have an issue I'd like to share.

I am trying to implement a sprite (a rabbit) who gets scared when the player gets close to him.

I thought of making around the rabbit a Area2D that will react to the player's getting inside (using the area_entered signal.
This Area2D is an excentered circle, the biggest part of the area is in front of him ( where the rabbit "looks"), and the smallest part of the circle is behind him.

In the game I am flipping left or right the rabbit according to his movements :

func walk(to:Vector2):
    if(to.x > 0):
        animatedSprite.flip_h = false
    if(to.x < 0):
        animatedSprite.flip_h = true
    #more code

But using this, the Area2D who is a child node of AnimatedSprite doesn't flip.

How would you do to have a scared area following the rabbit's eyes ?

Edit :
As the answer of Calm Turtle, I am changing the collapse area directly, it is good enough :

onready var initialPos = $CollisionShape2D.position

func walk(to:Vector2):
    if(to.x > 0):
        animatedSprite.flip_h = false
        $CollisionShape2D.position = initialPos
    if(to.x < 0):
        animatedSprite.flip_h = true
        $CollisionShape2D.position = - initialPos
    #more code
in Engine by (14 points)
edited by

1 Answer

+1 vote

The Area2D doesn't have a flip_h property, as such I don't believe it is able to "listen" to its parent and follow along. I could be off here, but that is my understanding of the situation.

A couple of recommendations:

Can you center the rabbit sprite in a way, that even when the sprite is flipped, it still is affected by the same Area2D? To put it another way, no matter which way the rabbit is facing, the hitbox is still the same.

Another solution is you could manually transform the Area2D when the sprite flips.

by (146 points)

Thank you for your answer. Yes I could center the area on the rabbit, but I want the rabbit to be less aware of what's behind him to be more realistic.
As you said I can transform the area's collision shape position directly, I have edited my question with code that does it.

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.