Skeleton2D Horizontal Flip

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

I’m learning about animations and how does Skeletons2D work in Godot, I’ve a walk animation and is working fine, but have a problem with the horizontal flipping when is walking right or left, i’ve done it like this:

var TurnRight = Input.is_action_just_pressed("ui_right")
var TurnLeft = Input.is_action_just_pressed("ui_left")

if TurnLeft == true:
	self.scale.x *= -1
if TurnRight == true:
	self.scale.x *= 1

If I press Right it works fine and if i press Left it flips and walks fine, but if i press Left again it flips again (because -scale.x * -1 = scale.x) and when is facing Left and press Right it does Moonwalk (bacause -scale.x * 1 = -scale.x)

How can I fix this? or Which is the correct way to make this flip?

Thnx

:bust_in_silhouette: Reply From: p7f

Have you tried replacing the value instead of multiplying?

var TurnRight = Input.is_action_just_pressed("ui_right")
var TurnLeft = Input.is_action_just_pressed("ui_left")

if TurnLeft == true:
    self.scale.x = -1
if TurnRight == true:
    self.scale.x = 1

I did it and does not work

checharor | 2020-08-06 02:01

:bust_in_silhouette: Reply From: checharor

I’ve upload the files here so you can test and see what’s going on i don’t get it

https://drive.google.com/drive/folders/1fO0nJTRIolcPFtAQXquAggDXRf6U1-Qk?usp=sharing

Ok, i need access to download that file.

p7f | 2020-08-06 02:26

Ok, sorry for that

checharor | 2020-08-06 08:26

Hi!
For how you made the scene, i used this and worked:

if GoRight == true:
	$Skeleton2D/AnimationPlayer.play("WalkL")
	velocity.x = SPEED
	$Skeleton2D/Hip.scale.x = 1

if GoLeft == true:
	$Skeleton2D/AnimationPlayer.play("WalkL")
	velocity.x = -SPEED
	$Skeleton2D/Hip.scale.x = -1

But note that the rotation of the hip will affect when you flip.

p7f | 2020-08-06 13:37