Initially, my goal is to supplement the current animation with a displacement, so that it smoothly transitions to it and this displacement affects the final result.
Something would look like this:
I tried to do it, but I don’t like how “jerky” it is.
And is it possible to move simultaneously along two axes, and not just, for example, along y?
This code is an example, maybe there is some simpler and more concise solution?
Adding @PatrickRyan as I am wondering what the simplest could be
@Monokuma215, in looking at your problem and PG, I’m not sure that I get exactly what you are trying to do so let me define what I think you are going for in case I am off base.
It appears to me like you have one animation that is playing - as in your first graph - and that you want to modify that motion with a second animation - to yield your second graph.
If this is the case, it seems to me that your PG is just making things hard on yourself. You could just use additive animation blending to modify your initial animation with additional offsets. The second animation clip would be the offsets you want to apply to the original curve as a vector3 so you can move along any axis. You then set a weight value on the blend and the interpolation between the base motion and the additive motion will be smooth. You can update that weight dynamically with a UI slider like this example. Or you can set up a third animation to animate the weight parameter of the additive blend to drive the transition using a smooth interpolation on an event.
I hope this helps you with the concept you are working on, but please ping back if I misunderstood your goals.
@PatrickRyan, thanks for the tip, I was looking for something similar. I don’t understand how additive animation blending works. I tried through MakeAnimationAdditive, but if I use fromFrame: 0, then it shifts sphere, to 0,0,0. I don’t really understand how this works, could you help me with this please.
@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.
This is amazing, thank you very much for the detailed answer. I apologize for the long answer, but you helped me a lot, thank you)