Blending form Mecanim to procedural animation

Hello everybody.
First of all, please forgive my future english mistakes, i’m french.

I need to blend between a mecanim animation and a procedural scripted one.
The mecanim part is easy, i just have to lower the layer weight to remove progressively the animation.
The difficulty come from the procedural part.

I know how to weight my procedural animation, but i don’t how to apply it properly over the mecanim result.

So far, i’ve gone this way :

public void LateUpdate()
{
    Quaternion incomingRotation = myBone.transform.rotation;
    Quaternion additiveRotation = Quaternion.Euler(0.0f, 1.0f, 0.0f); // Lets say it is the weighted procedural animation.
    myBone.transform.rotation = additiveRotation * incomingRotation;
}

So, basically, i take the rotation processed before the late update (supposed to be the mecanim one) and try to add my own rotation, expecting to have the resulting rotation.

But the bone keep rotating as if it is cumulating the additiveRotation of each frame.

Is there a way to do what i’m looking for ?

Thanks.

Doesn’t anybody has a clue about that ? I’m still blocked on this feature.

I found out a way to do what i was looking for :

void LateUpdate()
{
    Quaternion qBoneInitialRotation = myBone.transform.rotation;
    Quaternion qBoneProceduralRotation = WhateverYouWant();
    Quaternion qBoneResultRotation = Quaternion.Slerp(qBoneInitialRotation, qBoneProceduralRotation, fWeight)
    myBone.transform.rotation = qBoneResultRotation;
}

Works fine, allow me to blend smoothly between mecanim animation and procedural animation (without changing the animator layer weight f.y.i.)

If you want to save some ink:

myBone.rotation = Quaternion.Slerp(myBone.rotation, whateverRotation, fWeight);

I prefer to save some time for the next one who will have to read this piece of code.
Readability is very important :wink:

(b.t.w. it wasn’t exactly my code, i purposely simplified it for the forum ^^)

But thanks for the intention. :slight_smile: