extends CharacterBody3D var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") var speed = 5 var jump_speed = 5 var mouse_sensitivity = 0.002 @onready var camera_3d: Camera3D = $"Camera3D" func _enter_tree(): set_multiplayer_authority(name.to_int()) func _ready(): if !is_multiplayer_authority(): return; camera_3d.make_current() Input.mouse_mode = Input.MOUSE_MODE_CAPTURED func _input(event): if !is_multiplayer_authority(): return; if event.is_action_pressed("ui_cancel"): Input.mouse_mode = Input.MOUSE_MODE_VISIBLE if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: rotate_y(-event.relative.x * mouse_sensitivity) camera_3d.rotate_x(-event.relative.y * mouse_sensitivity) camera_3d.rotation.x = clampf(camera_3d.rotation.x, -deg_to_rad(70), deg_to_rad(70)) func _physics_process(delta): if !is_multiplayer_authority(): get_multiplayer_authority() return; velocity.y += -gravity * delta var input = Input.get_vector("move_left", "move_right", "move_forward", "move_backward") var movement_dir = transform.basis * Vector3(input.x, 0, input.y) velocity.x = movement_dir.x * speed velocity.z = movement_dir.z * speed move_and_slide()