Tutorial: Unity Animation 1 – The Animation window

The following notes are taken from the series of animation tutorials available from Unity’s Homepage.

1: THE ANIMATION VIEW

animation window

– Unity’s Animation Window allows the user to create animations without having to rely on any external software. For example, to animate a camera giving a flyby of a scene, the user can create this animation straight in Unity.

– To add an animation to a gameobject, select it then open the Animation Window. Beneath the playback controls is a dropdown menu where you can select, or create new animation clips. These are saved as separate files to your hard disk with a .anim suffix. Adjacent to this is the Sample number: the number of frames of animation per second.

– Beneath this, the ‘Add Curve‘ button allows you to add those properties you wish to alter during your animation, such as position, rotation, scale etc. Click the ‘+’ icon to add a property to the curve.

-To the right is the timeline, measured in frames and seconds, where keyframes for each curve are displayed. The red line indicates the current selected time. With the Record button activated, Any changes made to your object will add or alter a keyframe at this point. Keyframes can be dragged backwards and forwards to alter the timing of your animation. To preview you animation, click the Play button.

– At the bottom are two buttons to switch between ‘Dope sheet’ mode and ‘Curve’ mode. Curve mode is where you can fine-tune the easing of your animation, i.e the acceleration/deceleration rates. Right clicking on the curve, you can insert new frames. you can also right click to automatically adjust the curve.

– When you create the first animation on your object, Unity will automatically create an Animator controller in your project folder and add an animator component to your object. Animators handle animations for both generic objects and rigged objects such as humans. They are discussed further below.

– The created animation itself, which is a separate object in your project folder, has a few of its own properties. In the inspector panel you can set whether the animation loops, or only plays once.

2: ANIMATION PROPERTIES

– When you look at the inspector panel of an imported model, it has 3 tabs – Model, Rig ad Animation. In this section, we are interested in the Animation tab. Firt things first, in order to use any animations you created in a third party program, you must check the Import Animations box. This will open up a host of new options.

Bake Animations is used to convert animations created with Inverse Kinematics, to forward kinematics. Compress Animations is used to make your animations more efficient, at the cost of detail. Beneath this is a list of all animation clips currently stored in the model.

– The animation clip list includes the name, and the start and end frames of the models stored animation. You can add new clips by clicking the ‘+’ button, and choosing what frames it plays between from the timing section underneath. This includes a bar for the models entire animation timeline.

– Underneath is the Loop section. Check the Loop Time box to have an animation repeat when it is finished. Loop Pose can be checked to make Unity try to match the start and end poses of the model, for a smoother transition between animation cycles. Cycle Offset determines which point of the animation should be the start point. I.E a value of 0.5 would set the middle frame as the start point.

Root Transform Rotation, Position Y and Position X/Z are used if you want to prevent any movement of your gameobject, taken from the animations in the original model. For example, you may have animated a character walking forward in a straight line in an external program, but want him to walk on the spot in unity, so that any movement in game is handled via scripting and player input. To do this, check the ‘Bake into Pose‘ box under each heading.

– The remaining options in the Animation tab are discussed in more depth in a coming post.

3: ANIMATION CURVES AND EVENTS

– At the bottom of a model’s animation panel are the tabs Curves and Events. Curves can be used to define values over the length of an animation – i.e. a float value that can constantly change. This can then be fed into scripts for the desired effect. For instance, the value can be used to adjust the size of a collider whilst the player does a somersault.  Click the ‘+’ icon to add a new curve. Give the curve a name. Note that this curve name MUST be added as a float parameter to any Animator Controller that you wish to use the curve on.

– To edit your curve, double click on the graph window beside the name to open the graph and directly affect the curve. Double click on the curve to create new keyframes. Alternatively, scrub through the animation, and insert values manually by clicking the ‘Add Keyframe’ button just left of the curve, and inserting a value in the adjacent box.

– To find the value of a curve in a script, use the ‘Get Float’ function of the Animator component. This function will take the name of the curve as a parameter.

Events allow you to call functions from your scripts at different points in an animation – for example, if you wanted to play a sound effect when your character landed from a jump. To do this, expand the events tab, and scrub through the timeline to the point where you want the event to take place. Click the small button to the left of the Timeline to set up a new event.

– In the New event dialogue box, you must type the name of the script function you wish to call. This MUST be part of a script attached to the same gameobject as your Animator component. The boxes below are potential parameters for the function being called. See the Animator Scripting section further down for more info.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s