The speed attribute can be used to calculate the speed of a given property's change in value.
Speed is calculated by adding the word speed, all in lower case, after a property reference.
It will return a single-dimension output for the property's rate of value change,
and it will calculate the directional change on a multi-dimension value.
Okay, so let's use the speed attribute in an example.
Say you wanted to display the speed of this Rocket on the text readout layer here.
First things first, you're gonna open the Position property on the Rocket layer
by hitting "P" on your keyboard.
And this is so that we can pick whip the value.
Then, come to the Speed Readout layer, twirl down the layer's contents, go to Text,
Source Text, and "Alt + Click" (or "Option + Click" on a Mac) the stopwatch, to add a new expression.
So then, if you grab the Pick Whip tool, you can come down and let go over the
Position property on the Rocket layer.
So automatically, it's added some syntax for us, and it's referencing the Rocket layer's
transform.position property.
And specifically, it's referencing the X axis, which is the first index in the array.
This happens because we're using the Pick Whip tool to connect a single-dimension property,
which is the Source Text here, to a multi-dimension property, which is Position.
So, it's going to automatically just link to the first index in the array.
So, for this example, you can just remove the [0] from the end of the reference,
and now we can start to work with the speed attribute.
So if you click away from the expression field, you'll notice that the Speed Readout layer
is showing [Object Property] and that's because you're not actually giving it something to display.
But if you come back down to the expression and at the very end of the reference,
place your cursor and type .speed
Now you can click away from the expression field and now you'll notice it's giving us
this really cool number, which is representing the Rocket's current speed.
And now, if you scrub the playhead, you'll notice the speed readout layer is
updating the value in real time with the Rocket's speed.
And, to make this number a little prettier, we can clip the decimal point by adding
.toFixed, capital F, open parenthesis, 1, close parenthesis,
and this is gonna only display one decimal point past the period.
Another way you can use speed is to drive a particle emission value based on the speed of the source.
So, you might have noticed a Rocket Particles layer hidden under the Rocket.
Now, this layer already has CC Particle Systems II applied,
and it has an expression on the Position property.
And so, if you enable visibility on the layer, and scrub the timeline, you'll see that particles
are actually emitting behind the Rocket as it launches.
Now, there's already an expression applied to the Position property of the
CC Particle Systems II effect, and we'll go over this in more detail later in the course.
But this is a toComp conversion, which is looking at the Rocket source, and basically
this attaches the Source Point of the Position producer here
to the Rocket no matter where it is in the composition.
But, for now, we're just gonna deal with Birth Rate.
So, first, you want to add an expression to the Birth Rate property here in the Effect Controls panel.
So, I'm gonna "Alt + Click" (or "Option + Click" on a Mac) the stopwatch.
And it's gonna add some default syntax to your effect.
So, with this highlighted, if you grab the Pick Whip tool and drag it up to the
Rocket Position layer, and let go, it's going to add some default syntax,
and we're gonna remove this reference for the X axis
here at the end, so just remove everything in the brackets.
And then to replace the bracket, you're gonna type .speed
So once you click away from the expression field, you'll notice that the Birth Rate is
now going to drastically change as the Rocket launches.
And you'll see that it actually clips at 1000 here, halfway through the animation.
So this is a pretty large amount of particles, and you can actually trim this a little bit
by adding a division operator, and then I'm just gonna do 1600,
but you can do whatever number feels natural for you.
And so, if you click off the expression field, you'll notice that now we've trimmed
this number considerably back down to a more natural number.
So if you scrub the timeline, the Birth Rate is gonna go from 0 steadily up .1, .2, .3,
all the way to .5 and it eventually gets up to about 1.3 here
and then it slowly goes away.
And so now if you preview the scene, you'll notice that the Birth Rate is actually affecting
how many particles are coming out of the Rocket as it launches.
So you'll notice a couple particles come out of the back of the Rocket, right as it takes off
and then a bunch more come out behind it as the speed increases.
But the most important thing to note is that no particles are emitted if the Rocket is still.
And this is a really useful tool for an effect like Particular, where you can change the
number of particles emitted based on a source's speed.
The velocity attribute is very similar to speed, but it will output an array with
each dimension speed instead of a single speed.
Velocity, like speed, is calculated by adding the word velocity, all in lowercase, after
a property's reference.
The velocity attribute returns a multi-dimension output for the property's rate of value change.
Now, let's take a look at how to apply the velocity attribute.
If you come over to the existing expression, and select speed and toFixed,
and change it to velocity, you can then click away from the expression field
and you'll now get a three dimension array output.
The first number here before the comma is the X axis,
and the second value is the Y axis, followed by a comma,
and then the third number is for the Z axis.
So, if I scrub the timeline, you'll notice that only the Y axis is changing
and the X and the Z remain at 0 speed.
We'll cover arrays more in depth later in the course, but for now, you're just going
to add an index of bracket, 1, bracket to the end of velocity,
which is gonna target the Y axis instead of all three.
And now, if you click off the expression, you'll see the X and the Z axis disappear,
and we're left with the Y axis.
But you'll notice that the velocity is displayed as a negative value, unlike the speed,
which was a positive value.
This is how velocity works with a multi dimensional property.
It's not giving us the directional change, it's only giving us the Y axis change,
which is technically negative because the Rocket is moving up in the composition.
So, to fix this, we're just going to add a multiplication operator to the end, and then
and then a negative 1.
And this is going to times the entire value here by negative 1.
And now, if you click away from the expression field, the minus goes away,
and we're left with just the Y axis showing us the Rocket velocity.
You can find the velocity and speed syntax in the Expression Language Menu
under the Property category.
We've arrived at the end of Lesson 204: Calculating Speed & Velocity of Value Change.
If you enjoy this expressions course, consider purchasing the paid content.
It includes in-depth documentation, extra tutorial content, high definition videos,
and all the project files used in the training.
Your purchase will help to create more free courses like this in the future.