- Home /
What is the way to go for animating simple objects?
Unity has several ways to implement animation of elements on screen, and I don't really know which is the "correct" (best, more generic, most flexible) way to do this.
We have mecanim, which seems to be more oriented towards "things with bones" (i.e. characters) with all the animations graphs and whatnots but that it seems to be the "official way to go" nowadays, the (legacy) animation view, which allows us to make simple clips and play them, and some basic functions to move arond stuff that reminds me of that funny time I messed around with OpenGL.
Most of posts that talk about moving stuff points towars the basic functions, all stuff that points towards the legacy animation view seems to be from 2013 (before the mecanim arrival), and I haven't seen any tutorial oriented towards making siple stuff move around in mecanim.
So, right now, I just want to rotate a cube. Wow. Big deal. But today's cube rotation could be tomorrow spaceship movement, and I hope next week something a bit more interesting or complex.
So, should I try to go for Mecanim to do ultra simple things I've already done with some functions? Does anyone keep using the old animation view?
It's a god question and one that I have asked myself. I handle it ona case-by-case, or rather, project-by-project base. Generally, I try to avoid having different animatio nmethods in one project. Things like simple rotations can be done via code without any animations at all, and for things like doors, if you really want to use animations, the legacy system is more than enough. However, The mecanim state machine is indeed very powerful and if you know that you might be going into more complex behaviors, be it rigged characters or spaceships, then I would recommend taking the plunge and learning how to use mecanim.
The thing is that for what I've done, with simple code I had more than enough (displacements, rotations..) but I have a strong feeling that I'm not going the "right" way to do this.
Also, having that bloody legacy animation system does not help neither. Is legacy, but is recommended for some stuff. Then is not legacy. But maybe in some versions they will remove it.
What a mess... thanks for the answers, anyway. I'll stick for now with simple code animation... if in the future I have time to learn mecanim, I'll switch completely. Just in case.
Answer by Anton-Korhonen · Oct 31, 2016 at 03:16 PM
If you only want to translate, scale or rotate an object i would recommend writing a simple script that does these actions for you. There is no need to use an animation system for these operations and it keeps the project more simple and clean.
All in all it comes to your own preferences, but if you decide to go the non-scripting route, I would definitely recommend using Mecanim. Like you said, because you're just rotating a cube doesn't mean that's everything you need to do in the future. Mecanim is a very powerful animation system and you can't go wrong by learning to use it.
The future is ahead of us and there is no need to use any of the old legacy components.
Answer by doublemax · Oct 31, 2016 at 12:41 PM
I would recommend iTween. It's a free asset and it's so essential and so simple to use that i actually think it should be integrated into Unity.
https://www.assetstore.unity3d.com/en/#!/content/84
Most simple animations can be achieved with a one-liner.
But my main problem is that, having 3 ways to animate something on Unity, I want to know what's the proper/recommended way to animate something. Adding a fourth way just makes the problem bigger.
The recommended animation style is what you do by yourself and like to use. Why are there dozens of different types of antialiasing? Because everything comes down to the needs of the project you are developing.
There is no the way of doing animation. I think you saying "adding a fourth way just makes the problem bigger" is wrong kind of thinking. In my optinion it adds variety, flexibility and options. Just because there are dozens of ways of doing something doesn't mean the one you choose is wrong.
Regarding the answer of @doublemax: Tweening is a powerful and fast way of doing animation and assets like iTween and LeanTween are great to start with. Personally i would go with LeanTween because it hass less overhead than other alternatives.
In my project i use a combination of Cinema Director and the built-in $$anonymous$$ecanim.
Answer by nathanthesnooper · Oct 26, 2016 at 10:02 PM
I try not to use animator for things that don't need an animator or a ton of sprite refs
public int AnimateFrames;
void Start () {
InvokeRepeating ("AnimateUpdate", 0, 0.125f);
}
void AnimateUpdate () {
AnimateFrames++;
if (AnimateFrames % 4 == 0) {
this.transform.localPosition = new Vector3 (this.transform.localPosition.x, 1f / 32f, this.transform.localPosition.z);
}
if (AnimateFrames % 4 == 2) {
this.transform.localPosition = new Vector3 (this.transform.localPosition.x, 0, this.transform.localPosition.z);
}
}
But there's any official recomendation on this topic? I've already done this some times, but I feel like I'm doing something I shouldn't be doing, having all that stuff above to move things.
Your answer
Follow this Question
Related Questions
root motion on in place animation 0 Answers
I can't setting at once ModelImporter.sourceAvatar in script. 1 Answer
Manipulating an animation towards a target object (ie. The hand and arm lean towards the target) 1 Answer
Mecanim Example Scenes import warnings. 0 Answers
Animation depending on the Int value 0 Answers