camera clamping fix#2704
Conversation
That looks like a good reason to keep the clamping inside the setter indeed, so why pick the other solution? |
Two solutions that keep the clamping in the setter function are here. Solution 1:
Solution 2:
Reversed
|
|
Hi, I've been testing this PR on Daneel53's test build and good news first: Pitch clamping function works great. I'm finally able to have different min and max values for pitch limits for Free Rein. On the other hand, it seems to have broken PlayerMouseLook.SetFacing() calls, specifically the Vector2 and (int,int) overloads. These overloads are mainly used to "freeze" the player's view by self-referencing PlayerMouseLook.Yaw and PlayerMouseLook.Pitch or PlayerMouseLook.lookCurrent. Since the clamping function seems to output a negative value, passing PlayerMouseLook.Pitch causes the view to rapidly fluctuate between positive and negative values. An easy way to replicate this issue without mods:
The method call causing the issue above Same mod but I made the pitch values passed to SetFacing negative. As can be seen, if the value is derived from something else, it now works as expected. If the value passed is referenced from PlayerMouseLook.Pitch, then the output is reversed (if the value is saved and passed) or fluctuates (if the value is continuously passed). Thank you for your work! |
|
Closing in favor of #2797 |
Fix Camera pitchMin and pitchMax Clamping
Problem:
Expected behaviour of
pitchMin: limits how far you can look down.Expected behaviour of
pitchMax: 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 = 10andpitchMin = -90: look up to 10, but can only look down to -10 (even with pitchMin set to -90).pitchMax = 90andpitchMin = -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).