0 votes

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

asked Aug 5 in Engine by checharor (26 points)

2 Answers

0 votes

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
answered Aug 5 by p7f (3,284 points)

I did it and does not work

0 votes

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

answered Aug 6 by checharor (26 points)

Ok, i need access to download that file.

Ok, sorry for that

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.

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.