fixed mouse uncapture while jumping leads to flying bug

This commit is contained in:
2022-12-06 21:26:51 +01:00
parent 605ad26cc5
commit c3aaf104e2
2 changed files with 4 additions and 8 deletions

View File

@@ -71,5 +71,3 @@ transform = Transform3D(0.994703, -0.00611287, -0.102607, 0.101106, 0.238088, 0.
shadow_enabled = true
[node name="player" parent="." instance=ExtResource("1_1hi18")]
JumpVelocity = 5.5
gravity = 14.0

View File

@@ -42,7 +42,7 @@ public partial class player : CharacterBody3D
Vector2 inputDir = Input.GetVector("move_left", "move_right", "move_forward", "move_backward");
direction = (Transform.basis * new Vector3(inputDir.x, 0, inputDir.y)).Normalized();
if (direction != Vector3.Zero)
if (direction != Vector3.Zero && Input.MouseMode == Input.MouseModeEnum.Captured)
{
velocity.x = direction.x * Speed;
velocity.z = direction.z * Speed;
@@ -50,7 +50,7 @@ public partial class player : CharacterBody3D
//checks for movement and adjusts the character direction with camera roatation
playerResetPosition = Rotation;
camPosition = cameraCenter.Rotation;
playerResetPosition.y = camPosition.y * -1f;
playerResetPosition.y = camPosition.y * -1f;
Rotation -= playerResetPosition;
cameraCenter.Rotation = new Vector3(camPosition.x, 0, 0);
}
@@ -59,11 +59,9 @@ public partial class player : CharacterBody3D
velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed);
velocity.z = Mathf.MoveToward(Velocity.z, 0, Speed);
}
if(Input.MouseMode == Input.MouseModeEnum.Captured)
{
Velocity = velocity;
}
MoveAndSlide();
MoveAndSlide();
}
public override void _Input(InputEvent @event)
{