My raycast3D and camera controller just aren't cooperating and i dont know where the issue is

Im still really new to godot, and rn im working on a project that requires a 3rd person player controller and ive implemented the springarm and camera and i attached a script for the characterbody3d. i also put the raycast3d but i put it as a child of the characterbody instead of the camera because (firstly i dont think it would work that way in 3rd person) and i also wanted to make sure it would face where the player is facing rather than the direction of the camera. And i tested it out and well i have no bugs, but… i know i messed up somewhere i just dont know WHAT got me this result. Any help would be appreciated. my account is still new so i cant upload a video but heres a link to the yt - help lol

extends CharacterBody3D
#ref playraycast
@onready var playerRayCast = $RayCast3D

#ref camera shi
@onready var spring_arm: SpringArm3D = $SpringArm3D@onready 
@onready var cam: Camera3D = $SpringArm3D/Camera3D

@export var sens : float = 0.1

const SPEED = 5.0
const JUMP_VELOCITY = 4.5

func _ready() → void:
#Lock mouse to screen
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

func _unhandled_input(event: InputEvent) → void:
#Cam rotation
if event is InputEventMouseMotion:
   cam.rotate_y(deg_to_rad(event.relative.x * sens))
   spring_arm.rotate_x(deg_to_rad(-event.relative.y * sens))
   spring_arm.rotation.x = clamp(spring_arm.rotation.x, deg_to_rad(-60), deg_to_rad(45))

func _physics_process(delta: float) → void:
   #gravity
if not is_on_floor():
    velocity += get_gravity() * delta

   #jump
if Input.is_action_just_pressed("jump") and is_on_floor():
    velocity.y = JUMP_VELOCITY

if Input.is_action_just_pressed("quit"):
	get_tree().quit()
#input direction and the movement/deceleration.
var input_dir := Input.get_vector("left", "right", "forward", "back")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
	velocity.x = direction.x * SPEED
	velocity.z = direction.z * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	velocity.z = move_toward(velocity.z, 0, SPEED)

move_and_slide()

#player input or facing direction
if direction != Vector3.ZERO:
	#do the vector w how far the raycast shoud; reach 
	playerRayCast.target_position = direction * 3

#points 3 units forward based on the player's current rotation
	playerRayCast.target_position = -global_transform.basis.z * 3

#the raycast length 
playerRayCast.target_position = Vector3(0, 0, -3) 

if playerRayCast.is_colliding():
	var collider = playerRayCast.get_collider()