- Home /
Question by
Naktrem · Mar 18, 2018 at 09:54 AM ·
rotationquaternionlerpissue
Quaternion Rotation On Specific Axis Issue
Hello there,
I try to rotate a cube and I use quaternations, it works correctly on y axis but not working properly on x axis (Horizontal) hope you guys can help.
public class NewBehaviourScript : MonoBehaviour {
public Transform player;
Vector3 currentRot;
Quaternion rotation;
// Use this for initialization
void Start() {
}
// Update is called once per frame
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;
currentRot.x += 90;
rotation = Quaternion.Euler(currentRot);
}
else if (Swipe.Instance.IsSwiping(SwipeDirection.Down)) {
// Debug.Log("Entered Correctly Down");
Debug.Log(currentRot);
// currentRot.z -= 90;
currentRot.x -= 90;
rotation = Quaternion.Euler(currentRot);
}
transform.rotation = Quaternion.LerpUnclamped(transform.rotation, rotation, 0.01f * 10);
}
}
cuberotation.gif
(468.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Rotate children (Cards) on a panel (maybe using lerp, or another method?) 1 Answer
How to ROTATE an object without slowing the ends (lerp) 3 Answers
Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers
Clamped Turret Doesn't Want to Lerp the Other Way 2 Answers
How would I smooth out a Quaternion? 2 Answers