Fire the right number of shots per second at any frame rate
A gun set to eight shots a second fires six or seven on some screens, because a wait is thrown away at the end of every frame. This entry shows how to keep the leftover so the rate holds, including when one frame is long enough for two shots.
Why this works
Time that has already passed belongs to the player. If a gun throws away the part of the wait that ran over, every shot costs a little extra, and the loss depends on the machine. Carrying the overshoot into the next wait makes the rate a fact of the weapon.
When not to use it
Skip it for weapons that fire once per press, like a bow or a sniper rifle, where the player sets the pace. A carried leftover would only let a quick second press come early. Use a plain wait there.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 3 common mistakes and the fix
- 28 lines of example code with 5 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Fire the right number of shots per second at any frame rate" (read_entry fire-rate-with-carried-leftover-time) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP