0 votes

I use this function to move the player, but the flip doesn't work. when I try scale.x = -10 it seems to multiply by -1, thus constantly flipping in the opposite direction than a moment ago.

func _move() -> void:
    var horizontal := Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
    var vertical := Input.get_action_strength("move_down") - Input.get_action_strength("move_up")

    var vector := Vector2(horizontal, vertical)

    if vector == Vector2.ZERO:
        if current_state == 'run':
            _set_animation('idle')
else:
    if current_state == 'idle':
        if horizontal == 1:
            scale.x = 10
        elif horizontal == -1:
            scale.x = -10
        _set_animation('run')
        move_and_slide(vector.normalized() * move_speed)
Godot version 3.3.2.stable.official
in Engine by (141 points)

I solve the problem. most likely this bug is related only to this class, with other classes it works fine. You should either change the node type or replace scale.x with transform.x.x.

2 Answers

0 votes

Why are you using operator "else" ? It not appropriate.

Try it:

if vector == Vector2.ZERO:
    if current_state == 'run':
        _set_animation('idle')

if current_state == 'idle':
    if vector.horizontal >= 1:
        scale.x = 10
    elif vector.horizontal =< -1:
        scale.x = -10
    _set_animation('run')
    move_and_slide(vector.normalized() * move_speed)
by (27 points)
0 votes

Inverting:
scale.x*=-1

by (209 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 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.