Attention | Topic was automatically imported from the old Question2Answer platform. | |
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