<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ZoomyGames</title>
    <description>The latest articles on DEV Community by ZoomyGames (@zoomygames).</description>
    <link>https://dev.to/zoomygames</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4269295%2Fdca9463f-48ac-4d0a-91f1-5759c7b67a1c.png</url>
      <title>DEV Community: ZoomyGames</title>
      <link>https://dev.to/zoomygames</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zoomygames"/>
    <language>en</language>
    <item>
      <title>Why our pool balls sped up mid-roll (and 3 other bugs from a browser pool game)</title>
      <dc:creator>ZoomyGames</dc:creator>
      <pubDate>Fri, 27 Nov 2026 17:04:09 +0000</pubDate>
      <link>https://dev.to/zoomygames/why-our-pool-balls-sped-up-mid-roll-and-3-other-bugs-from-a-browser-pool-game-cjf</link>
      <guid>https://dev.to/zoomygames/why-our-pool-balls-sped-up-mid-roll-and-3-other-bugs-from-a-browser-pool-game-cjf</guid>
      <description>&lt;p&gt;We recently shipped a 3D &lt;a href="https://zoomygames.com/games/8-ball-pool" rel="noopener noreferrer"&gt;8 Ball Pool game for the browser&lt;/a&gt;: three.js, TypeScript, no engine. The first player feedback was blunt: &lt;em&gt;"ball speed increases and decreases anytime."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; "the physics feels wrong" turned out to be four separate bugs, and none of them were in the collision maths:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;physics stepped by frame time, plus a fast-forward hack;&lt;/li&gt;
&lt;li&gt;balls slipping off the table through the pocket mouth;&lt;/li&gt;
&lt;li&gt;the CPU freezing the game while choosing its shot;&lt;/li&gt;
&lt;li&gt;shaders compiling on the first shot.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Physics stepped by frame time, with a fast-forward on top
&lt;/h2&gt;

&lt;p&gt;The loop did the classic thing: &lt;code&gt;step(dt)&lt;/code&gt; with the frame's delta time. On top of that, an earlier "optimisation" ran physics 2-3 times per frame once every ball was slow, to cut the boring tail of a shot (a break went from 12 s to 7 s). Players saw exactly what we had built: balls &lt;em&gt;speeding up&lt;/em&gt; as they slowed down.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi39ad5350w0jd5chqlaw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi39ad5350w0jd5chqlaw.png" alt="Before: the speed curve drops, then jumps back up. After: one smooth slow-down" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fix is the boring, correct one (simplified):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;STEP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;            &lt;span class="c1"&gt;// don't spiral after a tab switch&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;STEP&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STEP&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="no"&gt;STEP&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;blend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;STEP&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// smooth at any refresh rate&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside &lt;code&gt;step()&lt;/code&gt; we always sub-step at 1/240 s, so the AI's look-ahead simulations produce the same paths as the real game. To make shots end sooner &lt;em&gt;honestly&lt;/em&gt;, we changed friction instead of time: deceleration is now &lt;code&gt;30 + 0.25 * v&lt;/code&gt; (units/s²) and shots settle in 2-5 s.&lt;/p&gt;

&lt;p&gt;Careful, though: break shots depend on that slow tail. A much stronger friction we tried potted nothing on the break.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Balls flew off the table through the pocket mouth
&lt;/h2&gt;

&lt;p&gt;A test harness that fires hundreds of shots found 13 of 356 balls leaving the table. Balls arriving slightly off the pocket's centre slipped through the gap between cushion and pocket and sailed into the void, leaving a frame nobody could finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1xgjekpv9ajv4d8o05y6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1xgjekpv9ajv4d8o05y6.png" alt="Before: a ball slips past the pocket over the rail. After: a small jaw point turns it into the pocket" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Real tables have "knuckles", the rounded jaw points either side of a pocket. Two small circular jaw points per pocket, plus a safety net (anything past the rail drops into the nearest pocket), took it to 0 of 357.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The CPU froze the game at the start of its turn
&lt;/h2&gt;

&lt;p&gt;Profiling showed a 180-270 ms freeze on a desktop at the start of every CPU turn, and up to 1.35 s with CPU throttling. The AI picked its shot by simulating about 170 candidate shots in one go.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvdiffe547gl03i53h0es.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvdiffe547gl03i53h0es.png" alt="Before: one huge frame. After: many frames, each with a little search inside the budget" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We turned the search into a generator and run it for ~5 ms per frame (simplified):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;searchShot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cand&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nf"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;pathBlocked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// cheap ray check first&lt;/span&gt;
    &lt;span class="nf"&gt;score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cand&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;simulate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                  &lt;span class="c1"&gt;// let the frame breathe&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// each frame, while it's the CPU's turn:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cheap "is the path blocked" check before each full simulation cut the work 4.5x. As a bonus, the CPU now pots 65% of its chosen shots instead of 53% on our test tables, because it wastes less time on hopeless lines. (It also got a human-paced cue swing, so it no longer shoots instantly.)&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The first shot of the first game stuttered
&lt;/h2&gt;

&lt;p&gt;About a second of jank on the first frame of the first game: shader compilation. three.js compiles a material's program the first time it's drawn. We now call &lt;code&gt;renderer.compileAsync(scene, camera)&lt;/code&gt; behind the title screen, &lt;em&gt;after&lt;/em&gt; applying the player's table and cue: a material that gains a texture map needs a new program, so warm up the final look, not the default one. The renderer also only redraws when something changed, which matters on a pool table that sits still most of the time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The lesson
&lt;/h2&gt;

&lt;p&gt;"The physics feels wrong" was a time-step bug, a geometry gap, a main-thread stall and a shader warm-up. If your game &lt;em&gt;feels&lt;/em&gt; off, profile and measure before you touch the physics constants.&lt;/p&gt;

&lt;p&gt;You can play the result free in the browser, on desktop or phone: &lt;a href="https://zoomygames.com/games/8-ball-pool" rel="noopener noreferrer"&gt;8 Ball Pool on ZoomyGames&lt;/a&gt;. We make free web games at &lt;a href="https://zoomygames.com" rel="noopener noreferrer"&gt;ZoomyGames&lt;/a&gt; and write up what we learn along the way.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>javascript</category>
      <category>threejs</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
