In this post I will try to explain how I implemented simple auto animation for
my characters based on their changing position in the scene (using mecanim and
a simple script).
Position and Rotation only
In the above example the only thing being manipulated is the objects
position and rotation (The animations are happening automagically)
First we need to load a Mecanim
and a model to attach an Animator component onto.
In my example I have used the classic unity model of
Kyle the Robot
and the standard
(Any model and controller will do).
Animation States and Variables
We can see that there are a few states and variables included in this
The variable we are interested in is
The value of
will determine the walk/run animation that mecanim wil animate for us.
Each Update() the
(Vector3) of the object is taken . This value is then passed to the animator
(if one exists) which sets the specified movement float ("
" in my example)
This is the difference between this frames transform and the previous
- This variable can be changed in order to get the desired effect. I found
that a value of 1 produced good movements for the prototype I was
Simply attach this script to your object that contains your character. Good
luck, let me know in the comments if anything needs explaining or if this
does not work for you :)