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 =)
2 Answers
2
j_y_k
January 9, 2011, 4:05am
2
Try changing this:
var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
To this:
var endRotation = Quaternion.Euler(degrees) * thisTransform.rotation;
system
November 19, 2011, 5:44pm
3
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
related: http://answers.unity3d.com/questions/171380/camera-relative-free-orbit.html
– cregox