Velocity is contuinously being appliied even though its requirements FALSE

Godot Version

4.7

Question

In the below code, the line that continues velocity still runs even if on the floor. Not even the Print statement runs, nothing is coming up on the Output Log! Its just the velocity applying line thats running for some reason. I know this because when I remove it the player stops sliding across the floor.
Yes, the Motion mode is on grounded, and the Up Direction is set to y = -1.


elif !is_on_floor():
	if LastPressedRight:
		print("MOMENTUM")
		velocity.x = move_toward(velocity.x, SPEED , SPEED * delta)
	else:
		print("MOMENTUM")
		velocity.x = move_toward(velocity.x, -SPEED , SPEED * delta)



Can you post the rest of your script?

If we’re only going by this code you’ve shared, it’s possible that both SPEED and -SPEED are being read as the same value for some reason, so more work may need to be done to invert SPEED.

Personally I’d use either 0 - SPEED or SPEED * -1 for the second parameter, like this:

elif !is_on_floor():
	if LastPressedRight:
		print("MOMENTUM")
		velocity.x = move_toward(velocity.x, SPEED , SPEED * delta)
	else:
		print("MOMENTUM")
		velocity.x = move_toward(velocity.x, 0 - SPEED , SPEED * delta)

If this doesn’t fix it then we need more info, like Gertkeno said.