- Home /
Question by
Sackwut · Feb 23, 2020 at 04:29 PM ·
quaternionquaternionsquaternion.slerp
Rotation by Quaternion Slerp problems
Im still facing issues with Rotation by either quaternion.Slerp or lerp. I do something wrong, but i cannot see it.
In this example, i just want to simply rotate the cover of a chest on the x axis by -45° The code looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestRot : MonoBehaviour
{
[SerializeField] GameObject chestCover;
private void Update()
{
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
{
StartCoroutine(OpenLootWindow());
}
}
private IEnumerator OpenLootWindow()
{
Quaternion startRot = chestCover.transform.rotation;
Quaternion endRot = Quaternion.Euler(-45, 0, 0);
float t = 0f;
while (t <= 1f)
{
chestCover.transform.rotation = Quaternion.Slerp(startRot, endRot, t);
t += Time.deltaTime * 0.8f;
yield return null;
}
chestCover.transform.rotation = endRot;
}
}
The start rotation values are 0,0,0. So he just need to go -45 in the x axis, but the result looks like this:
So can someone explain, what have i done wrong here? Why he is also changing, y and z axis?
Thanks in advance
chestcovertransform.jpg
(15.3 kB)
Comment
Your answer
Follow this Question
Related Questions
Clock script with custom time not working 0 Answers
Rotating clockwise or counter clockwise using Quaternions and PID 0 Answers
Stage selection problem 1 Answer
Rotation with respect to world instead of the object itself using Quaternion in unity 0 Answers
How to fix flipping Euler anlges? 0 Answers