Movement script help[

4.4

for reference I am only pressing W, for some reason the player moves strangely like they can only move in 4 angles

also wanted to include this but no its not just because im moving my camera fast

sorry for the short video file size limit, also its not much better when pressing left and right it does basically the same thing


movement code, this only happens when clamp is there (clamp is to limit player speed

What’s going on here and how can i fix it?

What’s local_velocity for? You aren’t using it…

I’d think you’d want the clamp right before the move_and_slide(); you’re potentially adding a bunch of stuff to velocity after you clamp it.

Also, velocity.normalized() will override your clamp, and probably not do what you want here; if you normalize a vector it makes it be of length 1.0 (unless it’s a zero vector, in which case it’s a math error and what you get really depends on who implemented the normalize).

If you wanted movement to always be 5 unless the player is stationary, you might want something like:

var frame_speed: float = SPEED * delta * 10

if Input.is_action_pressed("S"): velocity += basis.z * frame_speed
if Input.is_action_pressed("W"): velocity -= basis.z * frame_speed
if Input.is_action_pressed("A"): velocity -= basis.x * frame_speed
if Input.is_action_pressed("D"): velocity += basis.x * frame_speed

if is_zero_approx(velocity.length_squared()):
    velocity = Vector3.ZERO
else:
    velocity = velocity.normalized() * 5.0

The other thing is, you’re using basis.x and basis.z, which is the rotation relative to the node’s parent. Depending on the relationship there, you could get all sorts of weird behavior. You might want to consider calculating the angle based on something explicit, like the world-relative angle of the XZ vector between the camera and the player.

I’m not using local velocity that’s just left over

Fair enough.

update, it works but im running into some issues, the player cant jump anymore also if you know how I could stop the player when there not pressing anything that would be much appreciated.