In addition to other properties
animation clips have Curves and Events.
These are found at the bottom of the
animation's tab when you have a model selected
in the Project Panel.
Curves can be used to define values
over the length of an animation.
For instance, if we had a jumping animation
we could define a height value on a curve.
This height value could be set to match the
height of the model's torso during the
jump animation.
We could then retrieve that value in our scripts
and adjust the size of our model's collider with it.
In this way the model's collider would
accurately align with the model's movement.
Let's take a look at how to add an animation
curve to an animation clip.
Start by expanding the Curves drop-down.
Then click the + icon to add a new curve.
Next we should name the curve.
For our example we might name it something
like Jumpheight.
This curve name must also be added
as a float parameter to any animator controller
that you wish to use the curve on
or else you will not be able to access it.
There are 2 ways of editing the curve itself.
Clicking on the image of the curve
opens up the curve editor.
This is the best way for fine tuning a curve
where accuracy is important.
In the curve editor you can double click
on the line to create a keyframe.
and you can drag the keyframes around
to the appropriate values.
The curve can be reset by clicking one of the
default curve values at the bottom.
The other method to add values to a curve
is to scrub through the animation using
the preview window's scrubber.
You can then set keyframes at appropriate
times using the button just left of the curve.
To the left of the keyframe button is the
value display where you can set the value
for that keyframe.
Using the left and right buttons below the name
you can move between the keyframes
and set their values.
Unity will then automatically make a
smooth curve between them.
If you are blending between multiple clips
each with a curve of the same name
then an average value will be taken based
on the weight of the blending.
To find the value of a curve in a script
we use the Get Float function
of the animator component.
This function takes either the name
or the name hash of the curve as a parameter.
The return value is the value of the curve
at the moment the function is called.
For more information on the Get Float method,
getting values from animators,
or on animator scripting in general
see the lesson on animator scripting linked below.
Events allow us to call functions
in our scripts at different points
in an animation.
For instance, if we have a jumping animation
we may want to play a sound when the model lands.
This is easy to achieve by creating an event
at the point in the animation where the model's
feet land on the ground.
To add an event start by expanding
the Events drop-down.
You can then scrub through the animation
using the preview scrubber.
Add events using the button
to the left of the timeline.
This opens a window displaying the
properties of the event.
First is the name of the function
that is called.
This must be a function that is in
a script that is attached to the same
game object as the animator component
that plays the animation.
For our example let's pretend we have a script
with a function called Play Landing Sound.
We would type play landing sound
in our function property.
The following properties are potential
parameters for the function.
Only one can be used for a function call.
Which is used depends on the parameters
of the function that is being called in the event.
When blending between clips with events
all of the events will be called
so it's best to keep that in mind.
If you are going to use an event to play
a sound effect such as a footfall
you would probably want to limit the
number of times it can be played by checking
whether the sound is currently playing
before playing it again.
Otherwise you're likely to have multiple
versions of the same sound
playing simultaneously.
Subtitles by the Amara.org community