From 251b51f10b6a81092302d9611ae2594c21811db6 Mon Sep 17 00:00:00 2001 From: anyreso Date: Thu, 18 Apr 2024 15:55:07 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20camera=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entities/player/player.tscn | 2 +- entities/player/player_input.gd | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/entities/player/player.tscn b/entities/player/player.tscn index c892b4d..e9ea190 100644 --- a/entities/player/player.tscn +++ b/entities/player/player.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"] [ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/assets/vanguard.tscn" id="2_beyex"] -[ext_resource type="Shape3D" path="res://entities/player/collision_shape.tres" id="2_vjqny"] +[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_vjqny"] [ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"] [ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://weapons/space_gun/space_gun.tscn" id="4_lhn5w"] [ext_resource type="PackedScene" uid="uid://dn1tcakam5egs" path="res://weapons/space_gun/projectile.tscn" id="5_lvaut"] diff --git a/entities/player/player_input.gd b/entities/player/player_input.gd index f9889d2..ceaeb95 100644 --- a/entities/player/player_input.gd +++ b/entities/player/player_input.gd @@ -24,8 +24,6 @@ signal jumped signal fired_primary signal throwed_flag -var _mouse_position: Vector2 - func _ready(): var has_authority = is_multiplayer_authority() set_process(has_authority) @@ -38,7 +36,15 @@ func _unhandled_input(event: InputEvent) -> void: if event is InputEventMouseMotion: if mouse_mode == Input.MOUSE_MODE_CAPTURED: # retrieve mouse position relative to last frame - _mouse_position = event.relative * MOUSE_SENSITIVITY + _update_camera(event.relative) + +func _update_camera(relative_motion : Vector2, sensitivity : float = MOUSE_SENSITIVITY) -> void: + # clamp vertical rotation (head motion) + camera_rotation.y -= relative_motion.y * sensitivity / 100 + camera_rotation.y = clamp(camera_rotation.y, deg_to_rad(-90.0),deg_to_rad(90.0)) + # wrap horizontal rotation (to prevent accumulation) + camera_rotation.x -= relative_motion.x * sensitivity / 100 + camera_rotation.x = wrapf(camera_rotation.x, deg_to_rad(0.0),deg_to_rad(360.0)) func _process(delta): direction = Input.get_vector("left", "right", "forward", "backward") @@ -50,7 +56,6 @@ func _process(delta): _throw_flag.rpc() jetting = Input.is_action_pressed("jump_and_jet") skiing = Input.is_action_pressed("ski") - _update_camera(delta) @rpc("call_local") func _jump(): @@ -64,12 +69,3 @@ func _fire_primary(): func _throw_flag(): throwed_flag.emit() -func _update_camera(delta): - # clamp vertical rotation (head motion) - camera_rotation.y -= _mouse_position.y * delta - camera_rotation.y = clamp(camera_rotation.y, deg_to_rad(-90.0),deg_to_rad(90.0)) - # wrap horizontal rotation (to prevent accumulation) - camera_rotation.x -= _mouse_position.x * delta - camera_rotation.x = wrapf(camera_rotation.x, deg_to_rad(0.0),deg_to_rad(360.0)) - # reset mouse motion until next input event - _mouse_position = Vector2.ZERO