- Home /
 
Can someone explain this MouseMove script to me :)
Hi guys, i was wondering if you could explain something to me. I just made a script called mouse x basically its my own mouse move script :). But i came across a code that got me thinking why it is there and if i remove why it stops my rotation on the script. the script is here:
public enum RotationAxis {MouseX = 1} var RotationAxisX = RotationAxis.MouseX;
 
                var sensitivityX : float = 400f;
 
                public var minimumX : float = -360;
 
                public var maximumX : float = 360;
 
                public var rotationX : float = 0;
 
                var OriginalRotation : Quaternion;
 
               function start(){
 
               OriginalRotation = transform.localRotation;
 
               }
 
               function Update () {
 
                if(RotationAxisX == RotationAxis.MouseX){
 rotationX += Input.GetAxis("Mouse X") * sensitivityX * Time.deltaTime;
 rotationX = ClampAngle (rotationX, minimumX, maximumX);
 OriginalRotation = XQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
 transform.localRotation = OriginalRotation * XQuaternion;
 
               } }
 
               function ClampAngle (angle, min , max ):float {
 
                if(angle < -360f){ angle += 360; } if(angle >360){ angle -= 360;
 
                } return Mathf.Clamp (angle,min, max); } 
 
               
               basically its the "Function ClampAngle " line that contains the code i am talking about. the code of line is
 return Mathf.Clamp (angle, min, max); 
 
               
               this is the line of code that i am talking about if i delete this line of code it makes the x rotation completely stop and why is that :)
secondly i was wondering if someone can tell me what an Quaternion is :) thank you very much in advance :)
MCHALO
Answer by GesterX · May 01, 2011 at 12:23 AM
If you remove that line then your ClampAngle function does not return anything. You use this in the following line to set the X rotation:
rotationX = ClampAngle (rotationX, minimumX, maximumX);
 
               
               If ClampAngle does not return anything then the X rotation is never updated.
A quaternion is a mathemetical model to represent a rotation in a compact way. They are extremely difficult to understand fully and it's easiest to learn what they do by experimenting or modifying existing code.
http://unity3d.com/support/documentation/ScriptReference/Quaternion.html
Your answer
 
             Follow this Question
Related Questions
Mathf.Clamp() not working as expected. 4 Answers
A node in a childnode? 1 Answer
How do I find the inverse cosine ??? 1 Answer
Increase/reset speed on tilt 0 Answers