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:
![alt text][1]
[1]: /storage/temp/153111-chestcovertransform.jpg
So can someone explain, what have i done wrong here?
Why he is also changing, y and z axis?
Thanks in advance
↧