From 0e03ced3c6aeafe73ff2d3e96928b54c35ce11b8 Mon Sep 17 00:00:00 2001 From: null Date: Wed, 5 Nov 2025 18:20:49 -0600 Subject: [PATCH] Added some camera control by holding down middle mouse button. --- scenes/player.gd | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scenes/player.gd b/scenes/player.gd index 0c7a5dc..5223894 100644 --- a/scenes/player.gd +++ b/scenes/player.gd @@ -7,6 +7,10 @@ const MOVE_SPEED := 8.0 const ACCELLERATION := 30.0 const DECELLERATION := 40.0 const JUMP_SPEED := 4.0 +var mouse_sensitivity := 0.005 +var rotation_x := 0.0 +var rotation_y := 0.0 +var cameraMoveMode := false @export var camera_path: NodePath @onready var cam: Camera3D = get_node(camera_path) if camera_path != NodePath("") else null @@ -53,3 +57,21 @@ func _integrate_forces(state): if on_floor and Input.is_action_just_pressed("ui_accept"): linear_velocity.y = JUMP_SPEED + +func _input(event): + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_MIDDLE: + if event.pressed: + cameraMoveMode = true + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + else: + cameraMoveMode = false + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + + if event is InputEventMouseMotion and cameraMoveMode: + rotation_x -= event.relative.y * mouse_sensitivity + rotation_y -= event.relative.x * mouse_sensitivity + rotation_x = clamp(rotation_x, deg_to_rad(-90), deg_to_rad(90)) # Prevent flipping + + $Camera3D.rotation.x = rotation_x + rotation.y = rotation_y