<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[AI - Fitness Game Using Body Pose Detection (Difficulty: 3)]]></title><description><![CDATA[<p dir="auto"> </p>
<h2><a class="anchor-offset" name="key-topics-covered"></a>Key Topics Covered</h2>
<p dir="auto"> </p>
<ul>
<li><a href="/topic/86/introduction-to-variables">Using variables</a></li>
<li><a href="/topic/81/reading-from-a-table">Reading from tables</a></li>
<li><a href="/topic/296/graphic-effects-blocks">Graphic Effects</a></li>
<li><a href="https://www.forum.creaticode.com/topic/419/ai-for-body-part-recognition-premium-only" target="_blank" rel="noopener noreferrer nofollow ugc">Body Part Detection AI</a></li>
</ul>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="introduction"></a>Introduction</h2>
<p dir="auto"> </p>
<p dir="auto">In this tutorial, you’ll create a fitness game using AI-powered body pose detection. The game will display a target pose on the screen, and the player must quickly match that pose using their body.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6375abe6-43a0-42e8-b412-921e31f5af5a.gif" alt="6375abe6-43a0-42e8-b412-921e31f5af5a.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-1-start-a-new-project"></a>Step 1 - Start a New Project</h2>
<p dir="auto"> </p>
<p dir="auto">Create a new project in the CreatiCode Playground.<br />
Delete the sprite named “<strong>Sprite1</strong>” and rename the “Empty1” sprite to “<strong>Main</strong>”.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-2-enable-body-part-detection"></a>Step 2 - Enable Body Part Detection</h2>
<p dir="auto"> </p>
<p dir="auto">Add the body part detection block. Set debugging to “<strong>yes</strong>” to highlight the key body points on the video feed.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/263d1c4d-fe1d-4193-b928-e19f118d1106.png" alt="29ec46b8-175b-4b5f-90be-ef68fd78ad3b-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
A new table named “i” will automatically appear under the Variables category. Check its box to display it on stage.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0e41c5fa-9538-4ee5-a285-7687d4b08472.gif" alt="0e41c5fa-9538-4ee5-a285-7687d4b08472.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Once you run the program, you’ll see the body part markers on screen, and the table data will update in real time:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c2890b2e-b478-49f0-84e0-0727fbe2e099.gif" alt="c2890b2e-b478-49f0-84e0-0727fbe2e099.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
<strong>Note</strong>: To capture your entire body in the camera frame, you’ll need to stand farther away—but this makes it difficult to read the table data on the screen. A good solution is to <strong>work with a classmate</strong>: one person performs the poses in front of the camera, while the other monitors how the data in the table changes.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-3-add-the-squat-costume"></a>Step 3 - Add the Squat Costume</h2>
<p dir="auto"> </p>
<p dir="auto">Now, uncheck the “i” table and add a costume representing a squat pose. Use the costume named “Dorian-d”, and rename it “Squat”.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c54d7698-fb24-4b6f-b6ed-e30cf55bf876.gif" alt="c54d7698-fb24-4b6f-b6ed-e30cf55bf876.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Set its size to <strong>130</strong> and position it at the bottom right of the stage. This will serve as the first target pose.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6f23c3cd-a65e-4cbb-9d74-2fff4fcfef84.png" alt="6f23c3cd-a65e-4cbb-9d74-2fff4fcfef84.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-4-understand-the-squat-pose"></a>Step 4 - Understand the Squat Pose</h2>
<p dir="auto"> </p>
<p dir="auto">We know where each body part is, but we don’t yet know <strong>how to consistently recognize the squat pose</strong>. To do that, focus on the X-positions of these 4 parts:</p>
<ul>
<li>Left hip</li>
<li>Right hip</li>
<li>Left knee</li>
<li>Right knee</li>
</ul>
<p dir="auto">In a squat pose, the <strong>knees spread out wider than the hips</strong>. So:</p>
<ul>
<li><strong>Knee Distance</strong> = Right Knee X - Left Knee X</li>
<li><strong>Hip Distance</strong> = Right Hip X - Left Hip X</li>
</ul>
<p dir="auto">After we calculate these 2 distances, we can use them to determine when the player is in a squat pose.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/564edd7e-dbc2-43e3-b030-4bef8cfd2354.png" alt="564edd7e-dbc2-43e3-b030-4bef8cfd2354.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-5-read-data-from-the-table"></a>Step 5 - Read Data from the Table</h2>
<p dir="auto"> </p>
<p dir="auto">Create 4 variables to represent the X positions of these 4 body parts: “left hip x”, “left knee x”, “right hip x”, “right knee x”.</p>
<p dir="auto">Display the “i” table and note each part’s row number. For example, the left hip X position is in <strong>row 12</strong>, under the column <strong>x</strong>:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/9fbcfc48-51c3-4c06-8b09-3fe970bdc235.gif" alt="9fbcfc48-51c3-4c06-8b09-3fe970bdc235.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Therefore, we can read this value into the “left hip x” variable like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b4b307d3-d534-4905-b79e-67e82fa1272a.png" alt="48ef9065-aa52-4846-a0a0-ece0e53606a2-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Repeat this process for all 4 variables:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0be18871-0112-4283-92e7-a51738e1c6b0.png" alt="46aa8f81-a178-4ba0-a59d-ffabf38fa990-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-6-calculate-distances"></a>Step 6 - Calculate Distances</h2>
<p dir="auto"> </p>
<p dir="auto">Create 2 more variables:</p>
<ul>
<li>hip distance</li>
<li>knee distance</li>
</ul>
<p dir="auto">Now calculate the distances:</p>
<ul>
<li>hip distance = right hip x - left hip x</li>
<li>knee distance = right knee x - left knee x<br />
 </li>
</ul>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6afef777-da64-4740-ac19-d582ceecd6a1.png" alt="0a66bf99-a1e5-4366-9894-285493778f00-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-7-determine-pose-from-distances"></a>Step 7 - Determine Pose from Distances</h2>
<p dir="auto"> </p>
<p dir="auto">Create a variable called <strong>pose</strong>. Use a simple rule like the one below to classify the pose:</p>
<ul>
<li>If knee distance &gt; 2 times of hip distance, then it’s a <strong>Squat</strong></li>
<li>Otherwise, it’s <strong>Unknown</strong></li>
</ul>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/e2180bd6-0c6c-406d-8cb4-89b0b37c422b.png" alt="6f52d490-a270-45f4-b671-3f643a7f0b1a-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-8-organize-with-a-custom-block"></a>Step 8 - Organize with a Custom Block</h2>
<p dir="auto"> </p>
<p dir="auto">Group the logic for pose detection into a new block called “calculate pose”, and move the related code into it.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/106172b7-d8d9-42c9-b250-9a7ee68c6672.png" alt="17815e92-c6fa-44ff-ab73-939e4708d462-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-9-handle-invalid-data"></a>Step 9 - Handle Invalid Data</h2>
<p dir="auto"> </p>
<p dir="auto">Sometimes body parts are not detected and return a value of -10000 in the table.</p>
<p dir="auto">To avoid errors, only calculate pose when all 4 X values are &gt; -250.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/da78be0a-2bb2-44cd-84a9-4c471f43c4cf.png" alt="8de3dba3-dc3b-44e5-a4d2-f9abeb9c7c76-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-10-continuously-calculate-pose"></a>Step 10 - Continuously Calculate Pose</h2>
<p dir="auto"> </p>
<p dir="auto">Since the table updates continuously as the player moves, wrap the pose calculation inside a forever loop:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/16f8492c-e66f-481a-a12a-35934babe99e.png" alt="d18a8fac-b1e3-4863-afb8-4da7f244d2ae-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-11-detect-success"></a>Step 11 - Detect Success</h2>
<p dir="auto"> </p>
<p dir="auto">Now check if <strong>pose = “Squat”</strong>. If so, show a success message:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/54a5a239-bac6-4317-ae1b-893b8ed23853.png" alt="86acf572-f9f1-4fde-8e63-bc70d826472d-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Result:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/da8e2ea1-37b8-42a4-bcd5-ea13efe598e4.gif" alt="succ1.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-12-set-the-target-pose"></a>Step 12 - Set the Target Pose</h2>
<p dir="auto"> </p>
<p dir="auto">Now we have the basic game mechanics worked out. The next step is to make it more fun. We will give the player more than one target pose, so the player has to try to complete these poses to earn points.</p>
<p dir="auto">As a first step, we should create a new variable “target pose”, which will represent the next target pose the player needs to make.</p>
<p dir="auto">We can rewrite our code using this new variable:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/e6bfc84e-3b9b-465a-be37-aac0a11d0025.png" alt="f1930974-4250-489f-a3f2-63893c63b721-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-13-switch-between-squat-and-stand"></a>Step 13 - Switch Between Squat and Stand</h2>
<p dir="auto"> </p>
<p dir="auto">When the user has completed the target pose, we should change the target to a new pose. To keep it simple, let’s make the target toggle between 2 poses: “Squat” and “Stand”.</p>
<p dir="auto">We can define a new block “change target pose” for this purpose. If the value of “target pose” is “Squat”, then the next target should be “Stand”. Otherwise, if the value of “target pose” is not “Squat”, it must be “Stand”.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/9fe0582b-3bb8-49e4-a361-9211dc041ccc.png" alt="3f92d377-3152-473b-bcfd-532376dc2faf-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-14-create-the-stand-pose-costume"></a>Step 14 - Create the Stand Pose Costume</h2>
<p dir="auto"> </p>
<p dir="auto">To show that the target pose has changed, we should change the costume of the sprite as well.</p>
<p dir="auto">Please find the “Dorian-c” costume and add it to your sprite. Rename it as “Stand”.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/3d6287ea-0e49-48c3-a7dc-22ae6afdf1d7.png" alt="ccbb49ba-1841-4bbd-bdeb-91790727ddf6-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
We need to make some small adjustments to the costume. The leg on the left is reaching out sideways. We can select the whole leg and rotate it to an upright position:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/95c44680-a969-43d9-9720-23d2ffbb178c.gif" alt="leg.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
In addition, the head is looking sideways, which may confuse the player. We can remove this head, and copy the head from the “Squat” costume:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1c525d7f-c9c4-45c6-b4e5-6a90c6418e46.gif" alt="head.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-15-switch-costume-with-target-pose"></a>Step 15 - Switch Costume with Target Pose</h2>
<p dir="auto"> </p>
<p dir="auto">When changing the target pose, also update the costume accordingly:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/310f0323-ac61-46f1-b448-b8ecc45815d4.png" alt="ffaa0bc1-4366-4650-ba05-315bbdd2cf40-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-16-add-visual-sound-effects"></a>Step 16 - Add Visual/Sound Effects</h2>
<p dir="auto"> </p>
<p dir="auto">To give the player clear feedback that the target pose has been completed, we should show some visual effects. For example, we can make the sprite brighter for a short time before changing to the next costume. Also, we can play a sound for collecting a coin as well:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ca656302-bac9-4bdd-b694-8fed9a6001e8.png" alt="7b07560d-03f8-41fc-b935-9ab4b946f189-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-17-detect-the-stand-pose"></a>Step 17 - Detect the Stand Pose</h2>
<p dir="auto"> </p>
<p dir="auto">In the “calculate pose” block’s definition, currently we only check for the “Squat” pose. We also need to check if the player is in “Stand” pose. To keep it simple, we can still look at the distance between the knees and the distance between the hips. If the player is standing up, the knee distance should just be slightly more than the hip distance. For example, we can require that the knee distance is less than 1.2 times the hip distance:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b0982ae4-833c-4862-8c69-a546a10966d0.png" alt="1e58e459-0f12-44e7-93e9-f605f171133f-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Now our game is ready. Whenever the player hits a target pose, we switch to the next target:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6375abe6-43a0-42e8-b412-921e31f5af5a.gif" alt="6375abe6-43a0-42e8-b412-921e31f5af5a.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="additional-challenges"></a>Additional Challenges</h2>
<p dir="auto"> </p>
<p dir="auto">Here are some fun ways for you to build upon this project:</p>
<ul>
<li>
<p dir="auto"><strong>Game Rules</strong>: You can design different rules for playing the game. For example, you can give the player a time limit (e.g. 1 minute), and whoever earns more coins wins. You can also require the player to complete 60 target poses, and whoever finishes in the shortest time wins.</p>
</li>
<li>
<p dir="auto"><strong>Improve the Pose Detection</strong>: Currently we only look at knees and hips. You can also add additional checks on the arms. For example, you can require the arms to be held horizontally. You can compare the Y position of the wrists with the shoulders.</p>
</li>
<li>
<p dir="auto"><strong>Different Target Poses</strong>: You can try to use some other poses. For example, make the player do an “X” pose like below. You will need to use the X and Y positions of the wrists and ankles to detect such a pose. Note that you can also generate more positions using the AI image generation tool (first <a href="https://www.forum.creaticode.com/topic/1154/search-or-generate-sprite-images-using-ai" target="_blank" rel="noopener noreferrer nofollow ugc">generate an image</a> for a standing person, then <a href="https://www.forum.creaticode.com/topic/1876/ai-editing-images-generate-variation" target="_blank" rel="noopener noreferrer nofollow ugc">generate a variation</a>).</p>
</li>
</ul>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/31cb114d-7979-4809-aa66-c20cecbebd5b.png" alt="31cb114d-7979-4809-aa66-c20cecbebd5b.png" class=" img-fluid img-markdown" /></p>
<ul>
<li><strong>2-Player Mode</strong>: When 2 players are standing in front of the camera, both can be detected by the body pose detection engine. This allows you to create 2-player games. For example, whenever player A makes a pose, we set that to be the target for player B. This way, player B has to copy player A’s poses.</li>
</ul>
]]></description><link>https://forum.creaticode.com/topic/720/ai-fitness-game-using-body-pose-detection-difficulty-3</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 00:36:37 GMT</lastBuildDate><atom:link href="https://forum.creaticode.com/topic/720.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Oct 2022 11:48:02 GMT</pubDate><ttl>60</ttl></channel></rss>