Author Topic: MouseLook Bug  (Read 577 times)


  • Playmaker Newbie
  • *
  • Posts: 1
    • View Profile
MouseLook Bug
« on: June 16, 2014, 04:37:10 AM »
Hi all!

Found a little bug in the MouseLook action script.
On Enter the script will get the gameobject.transform euler X and Y rotations and stores them in RotationX and RotationY.
These values have a range of 0 - 360.
The MouseLook actions Minimum X/Y and Maximum X/Y use a range of -360 to 360.
In the DoMouseLook method it adds mouse input changes to the rotations, which is then constricted with the ClampAngle method. This is where things go wrong... when you compare 0 to 360 values with -360 to 360 values, this might happen: X rotation is 350 (what should be -15 for this script) and Maximum X = 80.
X rotation is thus higher than maximum and gets restored to 80. This is a situation i have when trying to seamless switch between camera's by having them look in the same direction, before switching to a state with mouselook.

My solution is to add a check to translate the 0-360 value to a 180 to -180 value, which also seems more logical to me than the min/max range 360 to -360. Ofcourse this check could also be located at the OnEnter where the initial rotations are retrieved, but it would seem more safer to me to place this where the actual comparisons are made, since rotations could be adjusted while the script is running.

Code: [Select]
static float ClampAngle(float angle, FsmFloat min, FsmFloat max)
if (angle > 180)
angle -= 360.0f;

if (!min.IsNone && angle< min.Value)
angle = min.Value;

if (!max.IsNone && angle > max.Value)
angle = max.Value;

return angle;