The inception[/font]
[font=verdana]A while back, after slowly becoming mad tweaking animations and movement behavior on our avatar, I decided to have some simple fun with Unity. See where the limit was and what's possible in a certain domain. Since I was obsessed with the character's animation, my attention was driven towards improving what our animator gave us in terms of natural movement. Even though the animations were quite good, I wanted some physics madness in there. So I went on a quest to mess with the bones of mecanim.
It turns out it's rather straightforward to activate the so called "jiggly bones". A few changes in your model before export does the trick. It does however require a great deal of value tweaking and physics engine know-how. You may follow this tutorial if you want to try it for yourself.
Here's what I could do as a quick 'n dirty test. This will *not* be in the game. Even if the effect could be nice, It is at the bottomest bottom of our priorities.[/font]
[font=verdana][/font]
[font=verdana]But doing this as a playful "what if" helped me learn a lot about how Unity works with animations and physics. Even better, I would never have thought of what I'm about to show if I hadn't gamed the system.
A few days later, the movement and animation finally polished, I found one last thing I could do, turn the head of the fox in the direction of where the avatar will go next. Providing a subconscious feedback on the movement. Using the head bone and overriding the animation, it should be possible. Right?[/font]
[font=verdana][/font]
[font=verdana]It turns out it is. This gif was taken when a bug prevented the fox to move or turn so you can clearly see that the head orientation is overridden (and a bit disturbing, sorry).
How to do it[/font]
[indent=1][font=verdana]
[color=rgb(51,51,51)]First, you have to get a reference to your head bone:[/color][/font]private void Awake(){ HeadBone = /*find the headbone in the hierarchy*/.transform;}
[indent=1][font=verdana]
[color=rgb(51,51,51)][color=rgb(51,51,51)]There's nothing to do to your model. All you have to do is use the LateUpdate function which is called afterthe internal update of the animations.[/color][/color][/font]private void LateUpdate(){ Quaternion look_at = Quaternion.LookRotation(Direction, new Vector3(0.0f, 1.0f, 0.0f)); look_at *= Quaternion.Euler(-90.0f, 0.0f, 0.0f); // Our models are rotated HeadBone.rotation = look_at;}
[indent=1][font=verdana][color=rgb(51,51,51)]You can do all sorts of crazy stuff with this.[/color][/font]
[font=verdana][color=rgb(51,51,51)]
[color=rgb(51,51,51)]
[color=rgb(51,51,51)]
The result
[/color][/color][/color][/font]
[font=verdana][color=rgb(51,51,51)]
[color=rgb(51,51,51)]
[color=rgb(51,51,51)]
[/color][/color][/color][/font][font=verdana]