Combining two Quaternion Slerps on an object

Hey all,

So, I have a game that requires rotation around a pipe on four cardinal axes, as well as turning along curved tracks. What I have currently that work independently are two Quaternion.Slerps, seen here:

// Turns transform around pipe
transform.rotation = Quaternion.Slerp(prevTurn, nextTurn, t);
// Turns transform as it hits curved sections
transform.rotation = Quaternion.Slerp(prevTwist, nextTwist, tPos);

So, these both work by themselves, but any combination I’ve tried has failed. But I need the object to be able to curve along these pipes and spin around them simultaneously. Any ideas?

Thanks! :slight_smile:

Quaternions can be combined with *operator, according to the documentation (http://unity3d.com/support/documentation/ScriptReference/Quaternion-operator_multiply.html).

So you can do for instance:

// Turns transform around pipe
Quaternion qPipe = Quaternion.Slerp(prevTurn, nextTurn, t);
// Turns transform as it hits curved sections
Quaternion qTurn = Quaternion.Slerp(prevTwist, nextTwist, tPos);

transform.rotation = qTurn*qPipe;

Not that qTurnqPipe and qPipeqTurn will create different combination. You may need to try with one or the other.