Сomplement the animation with another animation

@Monokuma215 I updated your playground, but it was a large rewrite of some of the logic. But I figured this would be a good example to drop in the docs for additive animation as our only additive animation example is using skeletal animation and it a complex example. This one should be simpler to follow.

Basically, what we are doing is setting up some animations and assigning them to animation groups. I did it this way because you can create several animations and add them to a group, then blend all at once with another animation group. This can give you a lot of flexibility over the motion of your assets, while also giving you some control over the timing of starting or stopping animations together.

The animations are authored in this way:

  • The baseline animation is set up in the way you wish, in this case animating along the line in the scene
  • The additive animation is set up to animate only the parameter we want to modify on the baseline animation. In this case, we want to raise the position.y value by 2 units, so the entire animation is set up with every key holding Vector3(0.0, 2.0, 0.0). This animation looks strange on it’s own, but when adding the keys of this animation and the baseline animation together, we achieve the behavior we want.
  • Setting the additive animation up as a Vector3 animation also allows us to modify any of the other axes which you asked about above. And there’s nothing that says the values have to be static, the additive animation can be as complex as you want, and its key values will be added to any other values in the baseline group.
  • With the two animations created, we set the offset animation group to isAdditive = true so that the group will add with any other group targeting the same mesh.
  • Ironically, we set enableBlending = false in this instance as enableBlending is for transitioning FROM the mesh’s original position TO the animated position. So you will see an interpolation from the starting position of the mesh blending into the animation. Enable this again if it is desired, but do not worry about this parameter affecting isAdditive because while they both deal with animation blending, they are separate concepts.
  • Setting the initial value of weight on the offset animation to 0.0 means there is no influence of the offset animation on the baseline animation. We then want to interpolate the weight of the animation group to 1.0 so that we see the mesh move off the baseline path to the offset path and then back to 0.0 to return to the baseline path. We can do that in several ways, but one easy way to do that and keep all of your animations in sync is to target the animation group’s weight parameter with another animation.
  • It may seem unintuitive to think about using an animation to modify another animation’s parameters, but we can do exactly that. I used scene.beginDirectAnimation to target the offset animation group and modified the weight parameter when setting up the animation.

You can see that I changed your createAnim function a bit to make it more abstract since we are using multiple types of animation (Vector3 and Float) as well as needing keyframes that are simple in some cases, and more complex in others. I also made some smaller tweaks to use a looping yoyo mode so that the example can be easily understood without needing to hit the play button multiple times.

I hope this helps you understand how to use additive animation. I will add this example and some updates to the additive animation documentation for future reference.

1 Like