First Person Movement

Godot Version:

Godot V4.2.1

Question:

Making first-person movement with acceleration isn’t too hard, but I’ve not found anything on this variant I’ve been thinking about:

How could it have acceleration, but as soon as I let go of one of the movement keys - that direction’s velocity instantly goes to 0.
Could you still use lerp() for that because if so I’ve got no clue how I can make it only lerp when accelerating.

It’s not actually for a serious project, I was just playing around with it and it didn’t work.

does this work for your use case?

if direction.x == 0.0:
    velocity.x = 0.0
if direction.y == 0.0:
    velocity.y = 0.0

I also wouldn’t recommend using lerp for acceleration, prefer move_toward as it isn’t frame-dependant when using delta like lerp will be.

1 Like

So you want to add acceleration? Then define a variable target_velocity and assigns its value instead of velocity, then after you set the target_velocity, do like this:

velocity = lerp(velocity, target_velocity, delta * 10.0)

You can decrease the 10.0 for more acceleration or increase for less.

You can also set the value of velocity to target_velocity directly whenever you want, using the if direction statement.

As @gertkeno said, you can also use move_towards. As I generally not use it, so I forgot how to use it. But lerp is not bad, you can use it, both will work.

Yes it has lerp, my question is how do I get the effects of lerping when starting to move, but instantly stop when releasing the mevement key?

1 Like

Thats what I said, you can do like this:

if direction:
    velocity = lerp(velocity, target_velocity, delta * 10.0)
else:
    velocity = target_velocity