This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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

in Engine by (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
by (3,505 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

by (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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.