I am trying to simulate the movement of a spinning top, with tilt and spin.
I have this tilt rotation set up, and it works perfectly:
float maxVel = 20f;
float vel_X = Mathf.Clamp(rb.velocity.z, -maxVel, maxVel); //clamping the values
float vel_Z = Mathf.Clamp(-rb.velocity.x, -maxVel, maxVel); //for some reason, these values only work inverted like this
vel_X = vel_X / maxVel; //making it a percentage of the maxVelocity;
vel_Z = vel_Z / maxVel; //making it a percentage of the maxVelocity;
Quaternion target = Quaternion.Euler(vel_X * maxTilt, 0, vel_Z * maxTilt);
targetTilted.transform.rotation = Quaternion.Slerp(targetTilted.transform.rotation, target, Time.deltaTime * smooth);
The object tilts in the same direction as my analogue stick.
However, I also want to add a spin rotation, around the Y-axis. But I haven’t been able to. One rotation breaks the other.
Thank you in advance for any help.