Skip to content

camera clamping fix #2704

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions Assets/Scripts/Game/PlayerMouseLook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public float Pitch
get { return cameraPitch * Mathf.Rad2Deg; }
set
{
value = Mathf.Clamp(value, pitchMin, pitchMax);
value = Mathf.Clamp(value, -pitchMax, -pitchMin);
cameraPitch = value * Mathf.Deg2Rad;
if (cameraPitch > piover2 * .99f)
cameraPitch = piover2 * .99f;
Expand Down Expand Up @@ -127,7 +127,7 @@ void ApplyLook()
sensitivityY = sensitivity.y * sensitivityScale;
}

Vector2 rawMouseDelta = new Vector2(InputManager.Instance.LookX, InputManager.Instance.LookY);
Vector2 rawMouseDelta = new Vector2(InputManager.Instance.LookX, -InputManager.Instance.LookY);

lookTarget += Vector2.Scale(rawMouseDelta, new Vector2(sensitivityX, sensitivityY * (invertMouseY ? -1 : 1)));

Expand All @@ -141,12 +141,11 @@ void ApplyLook()
}

// Clamp target look pitch to range of straight down to straight up
lookTarget.y = Mathf.Clamp(lookTarget.y, pitchMin, pitchMax);

lookTarget.y = Mathf.Clamp(lookTarget.y, -pitchMax, -pitchMin);
ApplySmoothing();

Yaw = lookCurrent.x;
Pitch = -lookCurrent.y;
Pitch = lookCurrent.y;
}

// Updates lookCurrent by moving it a fraction towards lookTarget
Expand Down