Hello,
here I’m stuck with quaternion usage (I know I’m not alone and that’s reassuring… a bit:)).
I have a cube. I want to make this cube rotates from 90 degrees on X axis or Y axis in worldspace.
Here is the code I use in the cube script :
void Update()
{
if (transform.rotation == _nextRot)
{
_currentRot = transform.rotation;
if (_onX == false)
{
_nextRot = transform.rotation * Quaternion.Euler(transform.up * 90);
_onX = true;
}
else
{
_nextRot = transform.rotation * Quaternion.Euler(transform.right * 90);
_onX = false;
}
_turntime = Time.time;
}
transform.rotation = Quaternion.Slerp(_currentRot,_nextRot, (Time.time - _turntime) * 0.2f);
}
As I understand it, using transform.up
or transform.right
and multiplies it by my rotation gives me a new rotation in worldspace. However this code gives me a cube rotating on X one time then only on Y axis.
Any idea?