• entries
    23
  • comments
    52
  • views
    33501

Fun with bones in Unity

Sign in to follow this  
FishingCactus

2250 views

[font=verdana]

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]jiggly_bones_350px.gif[/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]epistory_fox_head_move.gif[/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)]

fox_turn_head_subtle_350px.gif

[/color][/color][/color][/font]


[font=verdana]

[color=rgb(51,51,51)][color=rgb(51,51,51)][color=rgb(51,51,51)]Here you can see the result in game. Slowed down on purpose to make sure it's seeable in a gif. The effect is very subtle but you can see that the head will always point to the right direction (almost instantly) and the body follows soon after.
The next time you are frustrated with a particular task or simply bored out of your mind after a day of repetitive tweaks. Do yourself a favor and just play with the tools on your workbench. Who knows what kind of gem you'll unearth.[/color][/color][/color]

[/font]

Images

  1. reworked assets
  2. icemountain
  3. evolution 04
  4. evolution 03
  5. evolution 02
  6. evolution 01
  7. basic asset
  8. advanced asset2
  9. advanced asset
  10. 2015 01 16 envir01
  11. Bridge Cranks - Third Chapter
  12. Chapter 2 - Ice Mountain
  13. Chapter 2 - Ice Mountain
  14. Chapter 2 - Ice Mountain
  15. Chapter 2 - Ice Mountain
  16. Chapter 2 - Water Springs
  17. Chapter 2 - Water Springs
  18. Chapter 2 - Water Springs
  19. Chapter 2 - Water Springs
  20. Chapter 2 - Water Springs
View the entire Epistory album
Sign in to follow this  


3 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now