Animating skinned mesh along waypoints in Unity
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.
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.
- 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 position/rotation of xPos:
- Open animation panel
- Create new clip > name and place somewhere sensible like assets\animation
- 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)
- Set a keyframe on frame 0 with the <>+ button
- Move to next keyframe – Drag forward in the time line, marked by seconds – you may need to zoom in and out with scroll wheel
- Move and/or rotate SharkPos (keyframe will be set for you)
- 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.
- Repeat until animation complete
- 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.
- 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 :-)
10 ComentáriosInscrever-se nos comentários