Its giving me errors and I don’t know how to fix. I’m new. also I used A.I with some of it
extends CharacterBody3D
@export var mouse_sensitivity := 0.0025
@export var move_speed := 5.0
@export var jump_strength := 6.5
@export var gravity := 16.0
@export var pitch_limit := 1.5 # ~85 degrees in radians
Double jump flags
var can_jump := false
var can_double_jump := false
Look angles
var yaw := 0.0
var pitch := 0.0
@onready var camera = $Camera3D
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _unhandled_input(event):
if event is InputEventMouseMotion:
yaw -= event.relative.x * mouse_sensitivity
pitch -= event.relative.y * mouse_sensitivity
pitch = clamp(pitch, -pitch_limit, pitch_limit)
if event is InputEventKey and event.keycode == KEY_ESCAPE and event.pressed:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _physics_process(delta):
# Handle rotation
rotation.y = yaw
camera.rotation.x = pitch
# Movement input
var input_dir = Vector3.ZERO
var forward = -transform.basis.z
var right = transform.basis.x
if Input.is_action_pressed("Move_Forward"):
input_dir += forward
if Input.is_action_pressed("Move_Backward"):
input_dir -= forward
if Input.is_action_pressed("Move_Left"):
input_dir -= right
if Input.is_action_pressed("Move_Right"):
input_dir += right
input_dir = input_dir.normalized()
var horizontal_velocity = input_dir * move_speed
velocity.x = horizontal_velocity.x
velocity.z = horizontal_velocity.z
# Apply gravity
if not is_on_floor():
velocity.y -= gravity * delta
else:
velocity.y = 0
can_jump = true
can_double_jump = true
# Jumping
if Input.is_action_just_pressed("jump"):
if can_jump:
velocity.y = jump_strength
can_jump = false
elif can_double_jump:
velocity.y = jump_strength
can_double_jump = false
move_and_slide()