How to use two animations for a simple translation ?
Hello community ! I've been working on a simple task, yet I can't get it done :( I'm new to the whole animator and mechanim thing, and i apologise for mistake I may be about to say !
I have a simple component (let's say, a cube), on it i have an animator, with 2 animations named ZTranslation and XTranslation. The names are pretty explicit, it translates my cube from -1 to 1 on either X or Z axis. I have 2 Sliders, that must control the position of the cube on each axis, I can manage to link 1 axis on 1 slider, using:
anim.SetFloat("XTranslation", newValue);
When the slider is moved, newValue being the value of the slider, and XTranslation being a parameter (float) of the same name as my animation. Then i use this code in Update():
anim.Play("XTranslation", 0, anim.GetFloat("XTranslation"));
In order to place the cube at the right place and it works. However, the same code will NOT work with the Y axis as well since (i think) the cube is still affected by the older animation (the cube will NOT move, in any way when i move the slider).
If I move the animation blocks in each slider's linked method:
public void NewValuePosZ(float newValue)
{
anim.SetFloat("ZTranslation", newValue);
anim.Play("ZTranslation", 0, anim.GetFloat("ZTranslation"));
}
The cube will move on each axis, but it will always come back to it's default position in the other axis (I think one animation is overwriting the other).
So here is my question: How do I mix those animations to cover the whole (-1,-1,0) -> (1,1,0) possibilities ? Is there a transition to set in the animator for this ? I've read people about Blending but i can't figure out how to set this up, since i don't have a skeleton on my cube (and is it the solution ?).
Thanks for reading,
JRS
Answer by BimSekai · Oct 01, 2015 at 11:18 AM
Nevermind, I found it at last, by default the new layer have a weight of 0.... Changed the weight, set each layer as aditive and it worked like a charm.