Timers ARE dependent on framerate?
I'm programming a gun for my game in c++ UE4.13. I'm using Timers to handle the time between firing bullets, similar to the ShooterTutorial.
I've noticed that my weapon's firing rates vary depending on the framerate. This is especially noticeable on fast firing weapons.
I tried the same thing on the ShooterTutorial and I noticed the same problem. I even took a video: https://www.youtube.com/watch?v=tXsVe7y5XwM&feature=youtu.be (I set the machinegun to have a TimeBetweenShots to 0.075, the same firerate as the weapon in my game), the gun shoots significantly slower on 10fps than 30fps. It takes about 5 seconds to fire 50 bullets in 10fps, but 3.40 seconds to do the same on 30fps.
Are timers bad for weapon fire rates? I know it's not likely for someone to play a game at 10fps, but it's not unusual for a game to drop to 25 fps and even then it's noticeably shooting slower. It definitely feels like it shoots faster on high framerates too (but my computer can't record consistently at a high fps so I couldn't really test it).
TLDR: Using timers to handle weapon fire rates. Rapid fire weapons shoot noticeably slower during low framerates. Is this a bug or is there a better way to handle fast shooting weapons?
Any help is appreciated. Thanks in advance! :)
asked Oct 19 '16 at 05:09 AM in C++ Programming
No there is an option to set up a timer that works off of a variable and uses the value of the value as seconds so if you had a float with a value of 30 the timer would be set to thirty seconds.
answered Oct 19 '16 at 06:05 AM
You could define Tick(float deltaSeconds) on the actor, in this case the gun. It's a virtual function so you would have to override it, but you could just have the gun keep track of when it last fired and have the time since last shot variable get updated every tick. Essentially:
This might be more helpful if you still want to use timers: http://www.tomlooman.com/using-timers-in-ue4/
Follow this question
Once you sign in you will be able to subscribe for any updates here