- Home /
Quaternion amount/value of rotation?
Ok so I need to know how I can make this object(player controlled turret)which rotates on the Y axis to remember or get the value of the amount of a rotation that is happening, during a certain time.
What it does is rotates to a certain direction when a certain bool is true, which not using the input, as in you don't control it while this bool is true and while its rotating to this specific direction. So what I need is that specific amount of rotation that has happened on the axis while it rotates to said direction on its own.
Let me explain in code:
     Quaternion XQuaternion;
     
 //This is when the bool is not on and you are controlling the rotation with the Input of mouse.
     if(rTt != true){
     
        turretRotationX += Input.GetAxis("MouseX") * 1.6f * Time.deltaTime;
     
     }
     
    // So I want to do the same thing as above but not with the input but the amount the turret has rotated since the bool rTt has been true.
     
     if(rTt == true){
     
     //  turretRotationX += ??? AngleAxis? I don't how?
     
     
     
     }
     
    
     
 // This is where the mouse input goes into the rotation. // XQuaternion is what I want to change into the amount of rotation that has happened during rTt == true.
     turretRotationX = ClampAngle(turretRotationX, turretMinX, turretMaxX);
     XQuaternion =  Quaternion.AngleAxis(turretRotationX, Vector3.forward);
     
     //rot is the original rotation of the turret set in Start. Shouldn't be an issue here. 
     
     tur.localRotation = rot * XQuaternion; 
     
     
So yeah, please help.
It is hard to understand what you are asking. $$anonymous$$aybe this post will help you:
http://answers.unity3d.com/questions/26783/how-to-get-the-signed-angle-between-two-quaternion.html
Answer by DeadKenny · Nov 25, 2013 at 03:32 AM
Well you guys did help me a little in understanding my problem a little better, but I managed to avoid the whole thing by deleting it and replacing with:
     turretRotationX += Input.GetAxis("MouseX") * 1.6f * Time.deltaTime;
 
     transform.Rotate(turretRotationX , 0, 0);
This rotates without snapping.
However I don't know how to limit the angle when using transform.Rotate, because I need it for the barrel. Its fine like this for the turret though.
Answer by littlepsycho · Nov 24, 2013 at 04:41 PM
As far as I understand your question you want to modify the rotation of a GameObject.
Rotations are "stored" in Quaternions
 var rotation = Quaternion.Euler(10, 20, 30); // x:10, y:20, z:30
You can access the rotation on certain angels by
 Debug.Log(rotation.x) //Prints the x rotation -> 10
@littlepsycho - The Debug.Log() will not work. The rotation you produce is a Quaternion, which is a non-intuitive, 4D construct. The values of x,y,z,w will have values between 0.0 and 1.0. You can something like:
 Debug.Log(rotation.eulerAngles.x);
...but you are not guaranteed to get 10 back out. eulerAngles are derived from the Quaternion, and the eulerAngle representation can change.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                