Movement script help[

These lines are a good example of forcing axis-alignment

velocity.x = clampf(velocity.x, -5, 5)
velocity.z = clampf(velocity.z, -5, 5)

You would want to limit the entire vector’s length to 5, but instead you are clamping each axis to ±5, which means the player would move faster at 10u/s if they are diagonal to the world axis.

Using the dedicated .limit_length function avoids this because it takes both axis’ length into account and limits them combined according to pythagoras’ theorem.

velocity = velocity.limit_length(5)

Seems like you tried to fix this by using velocity.normalized() but you must get a warning along the lines of “this statement has no effect” because .normalized() does not apply the normalization instead making a copy. Eitherway best to remove that line as normalization isn’t what you need and would cause much more issues if this line was correct.


Then you are applying acceleration per-axis with each if Input..., again the player will accelerate faster if they are moving diagonally. Better to use Input.get_vector, transform it to a Vector3 matching your player’s direction and using move_toward over the entire vector at once. That’s what this section does:


Make sure to paste code instead of screenshots

1 Like