x


How do I rotate on World Axes with Quaternion.Slerp?

When I rotate my object using this script...

function RotateObject (thisTransform : Transform, degrees : Vector3, seconds : float) {
    if (rotatingNew) return;
    rotatingNew = true;

    var startRotation = thisTransform.rotation;
    var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
    var t = 0.0;
    var rate = 1.0/seconds;
    while (t < 1.0) {
        t += Time.deltaTime * rate;
        thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
        yield;
    }

    rotatingNew = false;
}

...the object rotates on it's local axes instead of the world axes.

What is a fairly simple way to get this to rotate on World Axes?

Thanks in Advance =)

more ▼

asked Jan 09 '11 at 02:37 AM

Heratitan gravatar image

Heratitan
314 20 22 29

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Try changing this:

var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);

To this:

var endRotation = Quaternion.Euler(degrees) * thisTransform.rotation;
more ▼

answered Jan 09 '11 at 04:05 AM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

Thank You! This was much simpler than I thought it would be.

Jan 09 '11 at 04:36 AM Heratitan

Could you explain what is the difference between these 2 orders?

May 10 at 08:58 PM toum
(comments are locked)
10|3000 characters needed characters left

After lots of testing, the pins remain in place, but following the combination of rotation is complete, the cube undergoes some rotation along the Y axis that is manipulating the "wheel" of rotation Z or Y. And I can not understand where the problem. Here is the code used ..

void Update () {
         if(switchControl == true && curTarget != null){
         if(curTarget.name == "RedR" || curTarget.name == "GreenR" || curTarget.name == "BlueR"){
          Quaternion curPlanchTargetRot = Quaternion.Euler(angles);
           curPlanche.transform.rotation = Quaternion.Slerp(curPlanche.transform.rotation, curPlanchTargetRot, 10f*Time.deltaTime);    
         }
       }

    void onMouseRotateDrag ()
    {
       float posInitX = initMousePosX;//position du curseur au moment du clic
       float posInitY = initMousePosY;
       float posCurX = Input.mousePosition.x;//position du curseur pendant le drag
       float posCurY = Input.mousePosition.y;

       differenceX = Mathf.Floor((posCurX-posInitX)/150);
       differenceY = Mathf.Floor((posCurY-posInitY)/150);
       curDifference = differenceX;
       if(Mathf.Abs(curDifference)<Mathf.Abs(differenceY)){//floor() valeur inf et ceil() valeur sup
       //    curDifference = differenceY;
       }

       if(curDifference != curApplyDifference){
         if(curTarget.name == "RedR"){ // axe X
          angles.x = ((-curDifference*90) % 360);
          curApplyDifference = curDifference;
         }else if(curTarget.name == "GreenR"){ // axe Y
          angles.y = ((-curDifference*90) % 360);
          curApplyDifference = curDifference;
         }else if(curTarget.name == "BlueR"){ // axe Z
          angles.z = ((-curDifference*90) % 360);
          curApplyDifference = curDifference;
         }
         posInitX = Input.mousePosition.x;
         posInitY = Input.mousePosition.y;
       }
    }

I need some help ... It's been three days I'm looking without much success

more ▼

answered Nov 19 '11 at 05:44 PM

Kalu gravatar image

Kalu
59 18 21 22

if you need some help, you should add this as a question. and if you wanted to call attention from ppl in this " thread ", then you could post comments. but above all, try to make your question clear. I can't understand what you're asking.

Nov 19 '11 at 08:06 PM Cawas
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x725
x441
x117
x109
x30

asked: Jan 09 '11 at 02:37 AM

Seen: 1831 times

Last Updated: May 10 at 08:58 PM