0 votes

{line 28} is returning when the result is negative or zero, but not when it is positive.
What's weird is that I am using the same (home made! ^^) formula at line 24 and, as tested, it is working for all cases, negative and positive.

Here's my code:

extends KinematicBody2D


### vars ###
var Matrix = Vector2()
var speed = 0
var speed_force = 500
var speed_max = 12000


# Called when the node enters the scene tree for the first time.
func _ready():
    pass


func _physics_process(delta):

    Matrix.x = 0


    speed += (int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left"))) * speed_force

    if(speed != 0 and not Input.is_action_pressed("ui_right") and not Input.is_action_pressed("ui_left")):
        speed += abs(speed) / speed * -1 * speed_force #line 24

    if(speed != 0 and ((Input.is_action_pressed("ui_right") and abs(speed) / speed != int(Input.is_action_pressed("ui_right"))) or (Input.is_action_pressed("ui_left") and abs(speed) / speed != int(Input.is_action_pressed("ui_left"))))):
        #speed *= 4
        print(abs(speed)/speed) #line 28

    speed = clamp(speed, -speed_max, speed_max)

    print(speed)

    Matrix.x += speed


    move_and_slide(Matrix * delta, Vector2.UP)
Godot version 3.3.3
in Engine by (16 points)

1 Answer

0 votes

bump

#
by (16 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.