- Home /
Question by
Naktrem · Mar 22, 2018 at 09:38 PM ·
rotationquaternionrelativerelative rotation
How to Rotate Relative To World
Hello there,
I want to make rotation relative to world by using Quaternion.Euler
My current code is following;
void Update() {
currentRot = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z);
if (Swipe.Instance.IsSwiping(SwipeDirection.Left)) {
// Debug.Log("Entered Correctly Left");
Debug.Log(currentRot);
currentRot.y += 90;
rotation = Quaternion.Euler(currentRot);
}
else if (Swipe.Instance.IsSwiping(SwipeDirection.Right)) {
// Debug.Log("Entered Correctly Right");
Debug.Log(currentRot);
currentRot.y -= 90;
rotation = Quaternion.Euler(currentRot);
}
else if (Swipe.Instance.IsSwiping(SwipeDirection.Up)) {
// Debug.Log("Entered Correctly Up");
Debug.Log(currentRot);
currentRot.z += 90;
rotation = Quaternion.Euler(currentRot);
}
else if (Swipe.Instance.IsSwiping(SwipeDirection.Down)) {
// Debug.Log("Entered Correctly Down");
Debug.Log(currentRot);
currentRot.z -= 90;
rotation = Quaternion.Euler(currentRot);
}
transform.rotation = Quaternion.LerpUnclamped(transform.rotation, rotation, 0.01f * 10);
}
Comment
Best Answer
Answer by Cornelis-de-Jager · Mar 22, 2018 at 10:19 PM
Try the following:
// Rotate Around World transform.Rotate (rotation, Space.World);
Thank you for the answer it worked, also it inspired me to use coroutines to make it smooth rotation.