0

I have several object rotating by itself in FixedUpdate().
Now I need to track rotation of one object, lets call it objX. Rotation goes only from 0 to 360 when I retrieve it. Is it possible to get rotation after 360 degrees?
For example when I use something like

float x = objX.transform.rotation.z;

variable x should be 560 degrees.
Is something like that possible?

filipst
  • 1,547
  • 1
  • 30
  • 55
  • add a counter to count rollovers and increment that + current rotation.z ? –  Oct 14 '14 at 10:40
  • I can't do that because I am rotating it with mouse, and when i pull mouse too fast it skips the point where i do the increment. – filipst Oct 14 '14 at 10:53
  • oh I see, maybe [THIS](http://answers.unity3d.com/questions/229681/tracking-object-rotation.html) –  Oct 14 '14 at 10:58
  • Not working. Still going from 360 to 0. – filipst Oct 14 '14 at 11:17

1 Answers1

0

Here is the way to track rotation.

Vector3 mouseClickPos;
    float angle;
    float lastAngle;
    int fullRotations;
    public float realAngle;

    void FixedUpdate(){
        mouseClickPos = Input.mousePosition;    
        Vector3 dir = mouseClickPos - Camera.main.WorldToScreenPoint(transform.position);
        angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
        angle-=90;
        if(lastAngle - angle > 270){
            fullRotations ++;
        }else if(angle - lastAngle > 270){
            fullRotations --;
        }
        Debug.Log(360*fullRotations + angle);
        Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
        transform.rotation = Quaternion.RotateTowards(transform.rotation, q, 6);
        lastAngle = angle;
    }
filipst
  • 1,547
  • 1
  • 30
  • 55