From 5a91798921356909598c5c1f9013c4d0eb3120d4 Mon Sep 17 00:00:00 2001 From: vaporvee Date: Sun, 1 Jan 2023 20:54:47 +0100 Subject: [PATCH] added back mouse capture --- src/player.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/player.cs b/src/player.cs index d0e7cee..af204e0 100644 --- a/src/player.cs +++ b/src/player.cs @@ -12,21 +12,24 @@ public partial class player : CharacterBody3D public float allDelta; public Marker3D camCenter; - //eveyrthing will be replaced with roatation and direction based movement - //camera global position will be included when calculating the player movement public override void _Ready() { camCenter = GetNode("camera_center"); } - public override void _PhysicsProcess(double delta) + public override void _Process(double delta) { allDelta = (float)delta; + if (Input.IsActionJustPressed("uncapture_mouse")) Input.MouseMode = Input.MouseModeEnum.Visible; + if (Input.IsMouseButtonPressed(MouseButton.Left)) Input.MouseMode = Input.MouseModeEnum.Captured; + } + public override void _PhysicsProcess(double delta) + { Vector3 velocity = Velocity; if (!IsOnFloor()) velocity.y -= gravity * allDelta; - if (Input.IsActionJustPressed("move_jump") && IsOnFloor()) + if (Input.IsActionJustPressed("move_jump") && IsOnFloor() && Input.MouseMode == Input.MouseModeEnum.Captured) velocity.y = JumpVelocity; Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward"); @@ -41,20 +44,18 @@ public partial class player : CharacterBody3D velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed); velocity.z = Mathf.MoveToward(Velocity.z, 0, Speed); } - Velocity = velocity; MoveAndSlide(); } public override void _Input(InputEvent @event) { - if (@event is InputEventMouseMotion mouseMotion) + if (@event is InputEventMouseMotion mouseMotion && Input.MouseMode == Input.MouseModeEnum.Captured) { Vector3 camRot = camCenter.RotationDegrees; camRot.y -= mouseMotion.Relative.x * mouseSensitivity; camRot.x -= mouseMotion.Relative.y * mouseSensitivity; camRot.x = Mathf.Clamp(camRot.x, minMousePitch, maxMousePitch); camCenter.RotationDegrees = camRot; - } } }