Animating skinned mesh along waypoints in Unity

September 20, 2011 in Rants & Raves

This post is a guide to importing a skinned mesh with a looping animation and then animating it’s position in Unity.
At the end of the guide you should been able to import a skinned mesh, parent it to a position node, animate positions & rotations along waypoints and then edit the animations, duplicate and move your mesh & animation path.

Export

From your 3D package, select your animated Mesh and export to an FBX – read the FBX export guide for more details. If it is the only object and animation in the file you could save a Native 3D file – e.g. MB or.max, but to keep things simple I like to export just what I need. Make sure you:

 

  • Set the keyframe range for one animation or export all animations and remember to set up splits in Unity or use @ name formating (see documentation on animation).
  • Choose whether to bake your keyframes or not;
    • Fluid curves and organic animations need fewer keyframes so you can export without baking.
    • Linear, Stop – Start type animations with and  flat curves to keep the accuracy you might want to bake keyframes.
  • Check your axis conversion, scale units etc.
  • Verify – I cannot say this enough it’s always good to re-import your export into the same package to ensure you get what you’re expecting.

Setup

  • In Unity select your exported/saved animated asset in the Project window.
  • Set your scale, animation splits and any other relevant stuff in the importer options in the Inspector.
  • Open or create a scene – Drag your animated model, lets call it Shark into the scene.
  • Create an empty object in the scene: from the Menu choose > Game Object > Create Empty – name it to SharkPos, where Shark is the name of your animated object and Position.
  • Move the empty SharkPos to the location of Shark, so you can use the gizmo from the same position. To position accurately you could copy and past the translation values.
  • Parent your Shark to the SharkPos object (this allows you to keep separate the animation of the position from the animated object’s idle/other animations).

Animate

  • Animate position/rotation of xPos:
    1. Open animation panel
    2. Create new clip > name and place somewhere sensible like assets\animation
    3. Move SharkPos to start position - Use gizmo to move object to desired position for start of your animation (this updates the translate value, so move a bit even if close to desired position)
    4. Set a keyframe on frame 0 with the  <>+ button
    5. Move to next  keyframe – Drag forward  in the time line, marked by seconds – you may need to zoom in and out with  scroll wheel
    6. Move and/or rotate SharkPos (keyframe will be set for you)
    7. Beware of  rotate values resetting -your rotation value can reset to 0 when you rotate past 180 degrees with the gizmo. If it does simply move the key in the graph to the correct value.
    8. Repeat until animation complete
 

Check the animation panel intro video for a more detailed look at the interface:  http://video.unity3d.com/video/3005614/animation-view-intro

Edit

  • To ensure a looping path, copy values from the first to the last keyframe – e.g click in the value of translation x, copy the number, go to the last keyframe click in the value and paste, and so on.
  • For Rotation values, to ensure consistent rotation direction, make sure the first and last are not the same value but 360 degrees apart e.g. first frame is y=-30 the last frame is y= 330.
  • To change the way your animation eases in and out of each keyframe right click the keyframe and choose the Tangents to edit and manipulate the handles – see editing curves for more info.
  • To edit timing, grouped keyframes can be moved and manipulated from the timeline (the diamond shapes at the top) to save moving and matching up keyframes from each channel.

Finalise

  • Parent to a new empty object – e.g.Shark01 this node can be used to move the whole animated object and path together.
  • Duplicate and/or move as necessary.

Two Hammerheads in your pool :-)

Comments (10)

Subscribe to comments
  1. hippocoder

    September 29, 2011 at 9:13 pm / 

    Oh look its Jason making silly text again.

  2. rea

    September 22, 2011 at 4:03 am / 

    #Olly: speaking of water4 is it possible to create an infinite water with it? or non-planar water surface (like river or waterfall)

  3. Jason Amstrad..

    September 21, 2011 at 1:33 pm / 

    I hope that they are already working on dynamic fluid surfaces.

  4. Olly Nicholson

    September 21, 2011 at 12:43 pm / 

    #All – thanks for those positive comments guys :-)

    #Ahmad – this is actually based on the Water4ExampleSimple prefab, with a custom mesh and tweaked settings – watch this space for a Tutorial soon…

    #Jan&#Marvin – I hope to make a number of assets available for my tutorials in the near future after my tech demo is finished – check back soon ;-)

  5. Jan Oonk

    September 21, 2011 at 5:20 am / 

    Hi Olly,

    thanks for this great guide. Would it be possible to put up a download link to the hammerhead skinned mesh?

  6. Francesco

    September 21, 2011 at 4:21 am / 

    I love sharks.

    Some time ago I developed a thing that was a mix of (animated, lookat, and AI).
    Take a look at this link
    http://www.francescogallorini.com/jaws-the-game/

    Francesco

  7. Marvin Friedrich

    September 20, 2011 at 8:03 pm / 

    These tutorials are great.

    I vote to bundle these tutorials up with the assets and scripts and put them in the asset store as free downloadable tutorials. I think that would be even more helpful.

    2¢,
    Marvin

  8. pixnlove

    September 20, 2011 at 2:09 pm / 

    I really enjoy these little tips, At one point or another they become really useful in any projects.
    We should definitly have more of these.
    Not long tutorial per say just useful tips and trick from the Gurus of the Unity team.

  9. Ahmad

    September 20, 2011 at 2:04 pm / 

    Olly,

    Is this water shown here the same as the Advanced Water prefab that was introduced in 3.4? Because for reason it looks a lot better here :)

  10. Olly Nicholson

    September 20, 2011 at 10:59 am / 

    Coming soon, how to make water ;-)

Comments are closed.