Animation cancels out script-controlled recoil.

I have a bunch of animations (all set up in the state machine thingy) and they all work just fine. I have a script that adds recoil to my gun. However, the animations cancel out the recoil coming from the script. How can I fix this without having to get rid of the animations and/or scripts?

Are you applying the recoil in LateUpdate()?

No, it’s a seperate function, called by another script in FixedUpdate().

Is there a reason why you’re calling it in FixedUpdate()? LateUpdate() is called after the animation system applies animations, so it’s the proper place to apply effects such as recoil. The exception is if you’ve ticked “Animate Physics” with Mecanim, in which case Mecanim updates animations in sync with FixedUpdate().

1 Like

TonyLi is right, you need to place your code in LateUpdate, otherwise it will be overwritten by the animation engine