From 9f85c39b02e1fb32c4b4158d763ad6df50fc3a32 Mon Sep 17 00:00:00 2001 From: Simon Ward Date: Fri, 23 Jan 2026 09:16:23 +1300 Subject: [PATCH 1/2] camera: made mouse control camera --- player/camera_gimbal.gd | 45 +++++++++++++++++++++++++++++++---------- player/player.tscn | 2 +- project.godot | 9 +++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/player/camera_gimbal.gd b/player/camera_gimbal.gd index 035053e..e3462cd 100644 --- a/player/camera_gimbal.gd +++ b/player/camera_gimbal.gd @@ -1,6 +1,12 @@ class_name CameraGimbal extends Node3D @export var rotation_speed = (PI / 180) * 120 +@export var shift_lock = false + +var locked_mouse_positon = Vector2(0,0) +var mouse_locked = false +var mouse_x_velocity = 0 +var mouse_y_velocity = 0 func reset(): basis = Basis() @@ -13,21 +19,38 @@ func rotate_camera_x(x, delta): Vector3.RIGHT, x * rotation_speed * delta) $InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x,-0.8,0.7) +func _input(event): + if event is InputEventMouseMotion: + mouse_x_velocity = event.velocity.x + mouse_y_velocity = event.velocity.y + func _process(delta): # rotate outer gimbal around y axis var y = 0 - if Input.is_action_pressed("cam_left"): - y += 1 - if Input.is_action_pressed("cam_right"): - y -= 1 - rotate_camera_y(y, delta) - - # rotate inner gimbal around x axis var x = 0 - if Input.is_action_pressed("cam_up"): - x -= 1 - if Input.is_action_pressed("cam_down"): - x += 1 + + if Input.is_action_just_pressed("shift_lock"): + if shift_lock == true: + shift_lock = false + else: + shift_lock = true + + elif Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or shift_lock == true: + if mouse_locked == false: + mouse_locked = true + locked_mouse_positon = get_viewport().get_mouse_position() + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + + if mouse_x_velocity > 200 or mouse_x_velocity < -200: + y -= clamp(mouse_x_velocity / 500,-5,5) + if mouse_y_velocity > 200 or mouse_y_velocity < -200: + x -= clamp(mouse_y_velocity / 1000,-5,5) + + else: + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + mouse_locked = false + + rotate_camera_y(y, delta) rotate_camera_x(x, delta) # reset gimbals diff --git a/player/player.tscn b/player/player.tscn index 10a0f29..5c9b486 100644 --- a/player/player.tscn +++ b/player/player.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=8 format=4 uid="uid://cfceg80unq0pe"] -[ext_resource type="Script" uid="uid://djeyfi7vm2vw0" path="res://player/player.gd" id="1_onrkg"] +[ext_resource type="Script" uid="uid://bfflnag3p4gen" path="res://player/player.gd" id="1_onrkg"] [ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera_gimbal.gd" id="2_onrkg"] [ext_resource type="Texture2D" uid="uid://cfb0gbwm57hm4" path="res://models/player_0.png" id="3_hqtel"] diff --git a/project.godot b/project.godot index 5a31f85..7d21883 100644 --- a/project.godot +++ b/project.godot @@ -87,9 +87,18 @@ backpack_3={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":51,"physical_keycode":0,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null) ] } +shift_lock={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} [layer_names] 3d_physics/layer_1="World" 3d_physics/layer_2="Player" 3d_physics/layer_3="Object" + +[physics] + +3d/physics_interpolation/scene_traversal="Legacy" From e5c1280dd902aa78b7fcffe01d284a7bacd085b9 Mon Sep 17 00:00:00 2001 From: Simon Ward Date: Fri, 23 Jan 2026 09:16:23 +1300 Subject: [PATCH 2/2] camera: made mouse control camera --- player/camera_gimbal.gd | 47 +++++++++++++++++++++++++++++++---------- player/player.tscn | 2 +- project.godot | 9 ++++++++ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/player/camera_gimbal.gd b/player/camera_gimbal.gd index 035053e..2f9e815 100644 --- a/player/camera_gimbal.gd +++ b/player/camera_gimbal.gd @@ -1,6 +1,12 @@ class_name CameraGimbal extends Node3D @export var rotation_speed = (PI / 180) * 120 +@export var shift_lock = false + +var locked_mouse_positon = Vector2(0,0) +var mouse_locked = false +var mouse_x_velocity = 0 +var mouse_y_velocity = 0 func reset(): basis = Basis() @@ -13,21 +19,40 @@ func rotate_camera_x(x, delta): Vector3.RIGHT, x * rotation_speed * delta) $InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x,-0.8,0.7) +func _input(event): + if event is InputEventMouseMotion: + mouse_x_velocity = event.velocity.x + mouse_y_velocity = event.velocity.y + func _process(delta): # rotate outer gimbal around y axis var y = 0 - if Input.is_action_pressed("cam_left"): - y += 1 - if Input.is_action_pressed("cam_right"): - y -= 1 - rotate_camera_y(y, delta) - - # rotate inner gimbal around x axis var x = 0 - if Input.is_action_pressed("cam_up"): - x -= 1 - if Input.is_action_pressed("cam_down"): - x += 1 + + if Input.is_action_just_pressed("shift_lock"): + if shift_lock == true: + shift_lock = false + else: + shift_lock = true + + elif Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or shift_lock == true: + if mouse_locked == false: + mouse_locked = true + locked_mouse_positon = get_viewport().get_mouse_position() + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + + if mouse_x_velocity > 200 or mouse_x_velocity < -200: + y -= clamp(mouse_x_velocity / 500,-5,5) + if mouse_y_velocity > 200 or mouse_y_velocity < -200: + x -= clamp(mouse_y_velocity / 1000,-5,5) + + else: + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + mouse_locked = false + mouse_x_velocity = 0 + mouse_y_velocity = 0 + + rotate_camera_y(y, delta) rotate_camera_x(x, delta) # reset gimbals diff --git a/player/player.tscn b/player/player.tscn index 10a0f29..5c9b486 100644 --- a/player/player.tscn +++ b/player/player.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=8 format=4 uid="uid://cfceg80unq0pe"] -[ext_resource type="Script" uid="uid://djeyfi7vm2vw0" path="res://player/player.gd" id="1_onrkg"] +[ext_resource type="Script" uid="uid://bfflnag3p4gen" path="res://player/player.gd" id="1_onrkg"] [ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera_gimbal.gd" id="2_onrkg"] [ext_resource type="Texture2D" uid="uid://cfb0gbwm57hm4" path="res://models/player_0.png" id="3_hqtel"] diff --git a/project.godot b/project.godot index 5a31f85..7d21883 100644 --- a/project.godot +++ b/project.godot @@ -87,9 +87,18 @@ backpack_3={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":51,"physical_keycode":0,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null) ] } +shift_lock={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} [layer_names] 3d_physics/layer_1="World" 3d_physics/layer_2="Player" 3d_physics/layer_3="Object" + +[physics] + +3d/physics_interpolation/scene_traversal="Legacy"