Building fast, deterministic timing and local 2-player games in vanilla HTML5 <canvas> looks deceptively simple—until a player on a 144Hz ProMotion display experiences double-speed rotation, or two players sharing one laptop keyboard get hit by membrane key ghosting.
While shipping a 100-level rotating-target timing game and same-screen duel mode, we ran into three subtle physics and input bugs. Here are the clean math and DOM patterns that solved them with zero external libraries.
1. Exact Chord-to-Angle Collision ( 2 * Math.asin(r / R) )
In rotating-pin games (inspired by classic aa / Coreball mechanics), pins stick into a spinning central wheel at orbit radius R , each with a circular pinhead of radius r .
If you integrate (x, y) positions frame-by-frame, floating-point rounding causes attached pins to subtly drift apart over long levels.…