Open ArshvirGoraya opened 1 month ago
A problem with this solution is a mod may rely on the clamping in the setter function, not the Update(). So, an alternative solution may be better.
That looks like a good reason to keep the clamping inside the setter indeed, so why pick the other solution?
That looks like a good reason to keep the clamping inside the setter indeed
Two solutions that keep the clamping in the setter function are here. I have implemented solution 2 in my last commit as it has the least problems.
pitchMin
and pitchMax
will have to swap their values. May not seem like a problem right now as currently the one with the lowest magnitude applies to both. However, if this change is implemented, modders may need to change the values around.
lookTarget
value. This will make it so that the player can set the target out of range if they move their mouse too far up or down. If they move the mouse upwards, the camera will be clamped correctly, but if they watn to move the camera down, they will have to move the mouse down much more so that the target is back within range before the camera can move down again. Here is a video of this problem. You can see that the target can go out of range and the camera cannot move in the opposite direction until the target is back within range: https://streamable.com/v1hgfnpitchMin
and pitchMax
being swapped, but doesn't have the lookTarget
problem of solution 1. With this pitchMin
controls how far you can look up, and pitchMax
controls how far you can look down.
pitchMin
and pitchMax
solution:lookTarget.y = Mathf.Clamp(lookTarget.y, pitchMin, pitchMax);
lookTarget.y = Mathf.Clamp(lookTarget.y, -pitchMax, -pitchMin);
I have implemented solution 2 in the previous commit and everything works as intended. I also tested with inverted mouse setting and everything works fine. Feel free to suggest any changes!!
Here is footage of everything working if anyone is curious: https://streamable.com/ujrcak
Fix Camera pitchMin and pitchMax Clamping
Problem:
Expected behaviour of
pitchMin
: limits how far you can look down. Expected behaviour ofpitchMax
: limits how far you can look up.Current Behaviour: Whichever value is closer to 0, sets both the minimum and maximum of how far the camera can look up/down.
Example:
pitchMax = 10
andpitchMin = -90
: look up to 10, but can only look down to -10 (even with pitchMin set to -90).pitchMax = 90
andpitchMin = -10
: look down to -10, but can only look up to 10 (even with pitchMax set to 90).Why its Happening:
This happens because the code clamps the pitch value twice. Inside the
update()
and inPitch
's setter function. This wouldn't be a problem if we weren't also switching the value's sign before the setter function, which results in the value being clamped in its sign-flipped state as well as its normal state.Examples
Positive Value:
Negative Value:
Solution:
Remove the
Mathf.Clamp()
call inside the setter function. The update function clamps this value anyway, so the clamping is still working, but just on Update().A problem with this solution is a mod may rely on the clamping in the setter function, not the Update(). So, an alternative solution may be better. Otherwise, those mods would have to update (e.g., clamp the value themselves before assigning to
Pitch
).