![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | JCNegar |
So, I’ve recently started learning GDScript, Trying to achieve a platformer-like movement, I had two ideas of doing it, The first one is using this:
// All variables and constants are set
func _physics_process(delta):
var input = Input.get_action_strength("RIGHT") - Input.get_action_strength("LEFT")
if input != 0:
velocity.x = move_toward(velocity.x, input * MAX_SPEED, ACCELERATION)
else:
velocity.x = move_toward(velocity.x, 0, FRICTION)
velocity = move_and_slide(velocity, Vector2.UP)
This code is working perfectly fine, HOWEVER, When I replace the:
velocity.x = move_toward(velocity.x, input * MAX_SPEED, ACCELERATION)
with:
velocity.x = lerp(velocity.x, input * MAX_SPEED , ACCELERATION)
It just doesn’t work and the player starts teleporting around, This bring us to my question, Why is that? I thought that lerp and move_toward did pretry much the same thing but I think I was mistaken?
Thanks in advance.