Sliding not working

Godot Version

4.2.2

Question

At the moment I am trying to add a sliding mechanic from a tutorial I am watching and I have looked over the video and don’t see anything wrong with my code I don’t know what is happening

this is the video:
Godot 4.X : Ultimate First Person Controller Tutorial Part 2 ( 2023 ) (youtube.com)

	if sprinting && input_dir != Vector2.ZERO:
		sliding = true
		slide_timer = slide_timer_max
		slide_vector = input_dir
		free_looking = true
		print("slide begin")

if sliding:
	slide_timer -= delta
	if slide_timer <= 0:
		sliding = false
		print("slide end")
		free_looking = false

	if sliding:
		velocity.x = direction.x * slide_timer * slide_speed
		velocity.z = direction.z * slide_timer * slide_speed

What exactly is going wrong with your code’s behaviour? Is it not sliding at all? Is the sliding going on forever? Can you provide more specifics?

From what I can see in the video and your code, the main difference I can see in the snippet is the lack of line 154 and 155 in the video, which say

if sliding:
	direction = (transform.basis * Vector3(slide_vector.x,0,slide_vector.y)).normalized()

I already have that code in the problem I should have stated was when I am running and then press crouch it doesn’t do anything if this helps here is more of my code

# Crouching
if Input.is_action_pressed("Crouch") || sliding:
	
	current_speed = crouching_speed
	head.position.y = lerp(head.position.y,crouching_depth,delta*lerp_speed)
	
	standing_collision_shape.disabled = true
	crouching_collision_shape.disabled = false
	
	# Slide Begin logic
	
	if sprinting && input_dir != Vector2.ZERO:
		sliding = true
		slide_timer = slide_timer_max
		slide_vector = input_dir
		free_looking = true
		print("slide begin")
	
	walking = false
	sprinting = false
	crouching = true
	
elif !ray_cast_3d.is_colliding():
	
	# Standing
	standing_collision_shape.disabled = false
	crouching_collision_shape.disabled = true
	head.position.y = lerp(head.position.y,0.0,delta*lerp_speed)
	
	# Sprinting
	if Input.is_action_pressed("Sprint"):
		current_speed = sprinting_speed
		
		walking = false
		sprinting = true
		crouching = false
	else:
		current_speed = walking_speed
		
	walking = true
	sprinting = false
	crouching = false

# handle sliding
if sliding:
	slide_timer -= delta
	if slide_timer <= 0:
		sliding = false
		print("slide end")
		free_looking = false

var slide_timer = 0.0
var slide_timer_max = 1.0
var slide_vector = Vector2.ZERO
var slide_speed = 10.0

@onready var head = $nek/head
@onready var standing_collision_shape = $standing_collision_shape
@onready var crouching_collision_shape = $crouching_collision_shape
@onready var ray_cast_3d = $RayCast3D
@onready var nek = $nek
@onready var camera_3d = $nek/head/Camera3D

I figured it out on my sprinting logic on the else I didn’t correctly tab the booleans about the state of the player it is fixed