- Home /
Object not moving after changing animator parameter
Hello!
I'm having problems with animations and animators in my 2d project, because i can't move an object after changing animation, by changing a parameter in the animator.
This is what i want to do:
Animate the object to go up and down in the air
Receive input
Change the current animation (sprite going up and down) to another animation that only changes the sprite of that object and switch physics on on that object
This is how trying to do it:
Create two animations (one that makes the object go up and down, that changes the position property of the object, and another one that only changes the sprite of the object, that only changes the sprite property)
Make the animation that goes up and down the default animation
Make a transition from the default animation to the animation, that only changes the sprite, that is triggered once a boolean parameter on the animator is set to true
Set the paremeter to true to trigger the second animation
Turn off "Is Kinemetic" (so that it can be affected by gravity and other forces)
This is what's happening:
The object goes up and down using the first animation
Input is received
The second animation starts playing (changing the sprite of the object) but the object does not move (it stays in the air and it is not affected by gravity or other forces, even though the "Is Kinemetic" is turned off)
This only happens when the second animation changes the position property of the object, so i would like to know why this is happening and/or how i can fix this. Thank you for reading this.
I did some more tests and it is the second animation that is locking the object at (0, 0, 0) but that doesn't happen if i only use that animation and no parameters.
I made some more tests and now i found out that the problem is that when going from one animation to the other, the second animation will lock the values of the properties that are in the first one, but not on the second one. This means that, since the first animation changes the position property but the second one doesn't, the position property on the second animation gets locked at (0, 0, 0) and i can't change it in the inspector (i also tested this with scale and got the same results). I also found this and now i don't know how to do it. Is there a way to "disable" a curve in the animation so that it gets controlled by code/physics again? If there is not, isn't that something that should be implemented?
Answer by curiouspers · Mar 06, 2015 at 01:24 PM
I know this tread is old, but i cant find any information for Unity 4.x how to use this, but i figured out, that you can use animation layers for 2d objects as well, and that do the trick.
So how i do it: Create a new layer for second animation, set weight to 1, blending override. Move animation state that only change the sprite to new layer, make transition from Any state to this animation. Set transition condition to use trigger (or boolean) animation parameter. You might also need another animation state for idle (with default sprite).
Hope it might help someone.