while (true) { // Each frame:
if (mouseClicked) {
animState.addAnimation(...); // Set new animations.
x = setup.value; // reset
}
x += additiveAnimation.value;
}
In this psuedo code x
represents a skeleton property and will increase every frame. Resetting x
needs to be moved outside the if
statement, so it happens every frame:
x = setup.value; // reset
x += additiveAnimation.value;
The interesting bit for additive animations is when other animations animate the values, then the additive animation is added to that:
x = setup.value; // reset
x = otherAnimation.value;
x += additiveAnimation.value;
This way your recoil can be on top of any animation. In this case you don't need to reset the value because the other animation is setting it. However, you may have many other animations and in all those you'd need to remember to key all the values used in your additive animations. When you forget, your additive animations will increase the value every frame. Resetting with setToSetupPose
or an animation ensures that won't happen.
Alyria should I mix in my setup pose animation on track 3 and then mix out my two recoil animations on 4 and 5 with emptyanimation tracks?
You don't need to mix in the reset animation. It probably sets the values to the setup pose. If your "main" animations (run, jump, etc on lower tracks) don't key the values keyed in the additive animations, they will be set to the setup pose by the reset animation without mixing in with an empty animation. If your lower track animations do key those values and you apply the reset animation on top, the values would snap to the setup pose + the recoil animations. It may be better to set your tracks like this:
0: the "reset" animation
1: main animations: idle run, jump, etc
2: recoil x (additive)
3: recoil y (additive)
This way if the main animations key the values changed additively, you get those keys + recoil. If the main animations don't key those values, you get the setup pose (from the reset animation) + recoil. You never get the values increasing every frame. 🙂