How to flip horizontally Sprite's children node ?

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

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
:bust_in_silhouette: Reply From: CalmTurtle

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.

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.

mustapha | 2019-03-28 07:05