+1 vote

Hi,

I have a "walking" animation (from left to right).
This is a skeleton animation (with IK chain) in a KinematicBody2D.
How can I flip this KinematicBody2D (and every items inside) horizontally with gdscript?

I tried the set_scale(Vector2(-1,1)), but the result is a "moonwalking" character :)

Thank you!

in Engine by (674 points)

2 Answers

+1 vote
Best answer

In my code I've resolved in this way:

var currentScaleX
var currentScaleY

func _ready():

       var currentScale = self.get_scale()
       currentScaleX = currentScale.x
       currentScaleY = currentScale.y

func _process(delta):

    if (  move_to_right ):
        self.set_scale(Vector2(-currentScaleX,currentScaleY))
    elif ( move_to_left ):
        self.set_scale(Vector2(currentScaleX,currentScaleY))
    else:
        ( idle )

-j

by (1,469 points)
selected by

Ahh you're right!
I used negative x in both directions... lol.

Sorry for the lame question, and thank you :)!

0 votes

i suggest putting sprites and possibly collisionshapes and rays into a sub node and flipping that subnode instead

by (43 points)
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 webmaster@godotengine.org with your username.