How can I control the animation in sync with the rate of fire of a turret (SkeletalMesh)
I have created a turret which shoots at my enemies. The Turret is a Blueprint which consists of a skeletal mesh which has an animation blueprint connected. In its animation BP I have created a state machine:
In my Turret Blueprint the "shoot logic" looks like follow:
What my turret now does is that it constantly plays my animation and spawns infinite bullets, so it is out of sync.
So the problem is that I need to add something like a rate of fire. But how would I achieve that with an animation Blueprint ? I have tried to use animation notifiers but they seem to have a bit of a delay ?!
asked Sep 21 '16 at 02:31 PM in Blueprint Scripting
Necro ... but anyway.
RoF is simply a delay between shots. 60 / RPM will return the delay value as a float.
Spawn projectile, Set Timer, Play montage. The montage play rate may need to be sped up to sync. So Take the duration of the montage and divide it by the delay.
700 RPM (0.0857 delay). Say the montage has a 0.233 duration. 0.233 / 0.0857 = 2.718786464410735
Set the Play rate of the montage to 2.7.
You will need to setup additional logic to ensure the RoF isn't bypassed. A common approach is to set a bool "Is Shooting" to true before you spawn the projectile. Then setup an Anim_Notify at the end of your montage to execute an event which sets the bool to false (so next shot can be fired). The downside to syncing to an animation is you're making ROF framerate dependent.
Animations have frame time. Each frame must be processed. At 60FPS the frametime is 16.67ms, At 30FPS it's 33.33ms. So this means regardless the RoF (0.086 as in example) the animation needs 7 frames to process before the anim_notify can be triggered .. thus 116.69ms delay.
If you decouple the montage from handling the bool reset. you can keep framerate independence.
Bool true -> delay (0.086) -> bool false
The downside to this is on low fps you can have multiple shots fired in a single animation cycle (multiple per frame). Similar to your turret. Meaning the animation might look like only one projectile was spawned, but in reality there where multiple.
answered Jan 24 '19 at 11:03 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here