Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MaxAnimator0817 |
{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)