Unity relative animations (Frequently asked but I don't get it)
Hello Community!
I'm struggling a bit with Mecanim. The problem is following:
I'm currently on a 2D Platform shooter with more fancy animations. The gameobject player actually looks at the mouse. His body is turning so that he faces the mouse and his gun points at it too.
Visualization (Note that the animator component is disabled, and that this behaviour is controlled by a script.):
If I now want to apply animations on this gameobject (for example walking and little knockbacks when shooting) the animator naturally overrides everything I do in the script on the gameobject (transforms, rotations etc).
Visualization (Note that the ches and head aren't pointing at the mouse anymore because they are now controlled by the activated animator for knockback animations):
Is there any way i can mix both? For example I want that when the player looks up and shoots, that a relative animation plays that pushes the upper part of the body a bit more back: When upper part is rotatet 35° then the knockback animation should push it 2 more degrees back = 37°, means for 40° => 42°, 17° => 19° and so on.
I don't honestly know if there is a better approach. Is my question clear? Let me know if you have problems understanding it.
Thanks in advance and have a nice day!
Answer by theANMATOR2b · Jul 20, 2017 at 12:40 AM
I won't suggest a method because I think this is part of the enjoyment of game development - solving problems that are attainable with the ability and knowledge we posses.
Here is a link to execution order in Unity. With this information I believe you'll be able to develop a system that works for your game.
I know that the animation plays right after Update() and as I read from other posts before LateUpdate() (I haven't confirmed that by myself or in the API), meaning that I could overwrite the animation in LateUpdate() making a script behaviour possible. However my first quick try was unfortunately not a success. I eventually missed something, so I will check it again.
Thanks for the hint! Of course the bare solution would indeed be boring, since I try to develop a system that I hope will satisfy me in my way of using animations in the future!