Here is what CharacterBody3D code looks like:
var speed
var Running
const WALK_SPEED = 10.0
const SPRINT_SPEED = 20.0
const JUMP_VELOCITY = 7.8
var accelerationx = 5.0
var dead = false
var animation_lock : bool = false
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = 18.8
@onready var camera = $Camera3D
@onready var Hand = $"CanvasLayer/Bare Hands/Hand"
@onready var Reaction = $CanvasLayer/LiveReaction/Reaction
@onready var PlayerTree : AnimationTree = $"CanvasLayer/Bare Hands/AnimationTree"
@onready var StateMachine : PlayerStateMachine = $PlayerStateMachine
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
camera.current = true
PlayerTree.active = true
func _unhandled_input(event: InputEvent) -> void:
if dead:
return
if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
elif event.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
rotate_y(-event.relative.x * 0.005)
camera.rotate_x(-event.relative.y * 0.005)
camera.rotation.x = clamp(camera.rotation.x, -PI/4, PI/3)
```