Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mouse look jitter (partially) #394

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Prefabs/Input/PlayerInput.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
playerInput: {fileID: 0}
mouseLookScale: 0.1
mouseLookScale: 0.0015
gamepadLookScale: 1
ZoomActive: 0
--- !u!20 &-8626314750790423148
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/Control&Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public class InputManager : MonoBehaviour
public Vector2 lookInput { get; private set; } = Vector2.zero;

[SerializeField]
private float mouseLookScale = 0.1f;
private float mouseLookScale = 0.02f;
[SerializeField]
private float gamepadLookScale = 0.75f;

private bool isMouseAndKeyboard = false;
public bool IsMouseAndKeyboard => isMouseAndKeyboard;

public bool ZoomActive = false;

void Start()
Expand Down
7 changes: 4 additions & 3 deletions Assets/Scripts/Control&Input/PlayerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void OnCrouch(InputAction.CallbackContext ctx)
}
StartCrouch();
}

if (ctx.canceled)
{
animator.SetBool("Crouching", false);
Expand All @@ -216,7 +216,7 @@ private void OnCrouch(InputAction.CallbackContext ctx)
isDashing = false;
onLanding -= StartCrouch;
}

}

private void StartCrouch()
Expand Down Expand Up @@ -301,7 +301,8 @@ private void UpdatePosition(Vector3 input)
private void UpdateRotation()
{
var lookSpeedFactor = inputManager.ZoomActive ? LookSpeedZoom : lookSpeed;
aimAngle += inputManager.lookInput * lookSpeedFactor * Time.deltaTime;
var lookInput = inputManager.IsMouseAndKeyboard ? inputManager.lookInput : inputManager.lookInput * Time.deltaTime;
aimAngle += lookInput * lookSpeedFactor;
// Constrain aiming angle vertically and wrap horizontally.
// + and - Mathf.Deg2Rad is offsetting with 1 degree in radians,
// which is neccesary to avoid IK shortest path slerping that causes aniamtions to break at exactly the halfway points.
Expand Down