Enemy $AnimatedSprite.flip_h according to where he's facing

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

Ok, guys, I really need your help. I am having some troubles with setting each “flip h” accordingly. I need my enemy to flip horizontaly and face the opposite each time it collides. I do get the first “flip h” but then it stops flipping and just playing the running animation. Long story shortm I just want it to face whatever direction it’s facing.

func _ready() -> void:
	set_physics_process(false)
	_velocity.x = -speed.x / 2
	$AnimEnemigo.play('Correr')

func _physics_process(delta: float) -> void:
	_velocity.y += gravity * delta
	if is_on_wall():
		_velocity.x *= -1
		$AnimEnemigo.flip_h = false
	
_velocity.y = move_and_slide(_velocity, FLOOR_NORMAL).y

Oh, and if you can help me with limiting its reach so it doesn’t fall. I assume Raycast2D has to do anything with it. If my english is a little weird is because my first language is spanish.

:bust_in_silhouette: Reply From: Mike Trevor

try:
$AnimEnemigo.flip_h = _velocity.x < 0
or
$AnimEnemigo.flip_h = _velocity.x > 0

Worked perfectly, it flips correctly. Thank you

Colorado-CL | 2020-04-02 13:38