Help with my sprint

Godot Version



I have been trying to make some first person controls and I wanted to put a sprint key in and I did successfully but when I am facing at a angle and walking it will move me in an angle but when I am going straight then it won’t could someone help me figure out what to do with it here’s my code.

~# Get the input direction and handle the movement/deceleration.
~# As good practice, you should replace UI actions with custom gameplay actions.
~var input_dir = Input.get_vector(“Left”, “Right”, “Forward”, “Back”)
~var direction = (Neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
~if direction:
~~velocity.x = direction.x * SPEED
~~velocity.z = direction.z * SPEED
~~#Check if sprinting
~~if Input.is_action_pressed(“Sprint”):

~~~velocity.z *= SPRINT_VELOCITY 
~~if Input.is_action_just_released("Sprint"):
~~~velocity.z /= SPRINT_VELOCITY

You’re missing the velocity.x to go with velocity.z, X and Z are the walking plane where Y is for controlling jumps/gravity.

if Input.is_action_pressed("Sprint"):
    velocity.x *= SPRINT_VELOCITY
    velocity.z *= SPRINT_VELOCITY

On formatting, when I said (`~) key i meant to paste code after three ticks, I did the example above like so, not by putting squiggly marks instead of tabs

if Input.is_action_pressed(“Sprint”):
    velocity.x *= SPRINT_VELOCITY
    velocity.z *= SPRINT_VELOCITY