<?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[2D Physics - Water Simulator (Difficulty: 3)]]></title><description><![CDATA[<h2><a class="anchor-offset" name="introduction"></a>Introduction</h2>
<p dir="auto">In this tutorial, you will use the 2D physics engine to build an interesting animation: simulating water in a bucket.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b8ca45b4-7ba0-4995-99c8-64a185221fc9.gif" alt="bu5.gif" class=" img-responsive img-markdown" width="489" height="404" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-1-initialize-the-2d-physics-world"></a>Step 1 - Initialize the 2D Physics World</h2>
<p dir="auto">Please create a new project on the CreatiCode platform, and delete the dog sprite. In the empty sprite, add the following blocks to initialize a 2D physics world.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ef25955e-14c7-4086-aca9-24230dcd841a.png" alt="03204fc3-b334-4ad1-a7d2-c4e2cca7326d-image.png" class=" img-responsive img-markdown" width="547" height="157" /></p>
<p dir="auto"> <br />
The physics world is not visible to us, and it is managed by the 2D physics engine. We can not use any other blocks in the “2D Physics” category without this step.</p>
<p dir="auto">In this program, we are setting a gravity in the Y direction for -100. Since the number is negative, it means objects will be pulled down along the Y direction.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-2-add-a-ball-costume"></a>Step 2 - Add a Ball Costume</h2>
<p dir="auto">We will use small balls to represent water drops. Please switch to the costume tab and add the “Ball-b” costume:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f4a29ac3-6f66-4d21-b2df-9bfd502df28e.png" alt="ebd799f5-284c-4665-ace0-8dbd8a319901-image.png" class=" img-responsive img-markdown" width="1208" height="747" /></p>
<p dir="auto"> <br />
Please also make the sprite smaller by setting its size to 30%:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/5007caab-0990-4a4d-8eae-b8b5db35ad25.png" alt="88dd569e-db3b-47e0-a623-026825e0b974-image.png" class=" img-responsive img-markdown" width="429" height="195" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-3-make-the-ball-follow-the-mouse"></a>Step 3 - Make the Ball Follow the Mouse</h2>
<p dir="auto">Next, let’s make the ball move to right above our mouse pointer’s position whenever we press down the mouse. We can use a forever loop that checks if the mouse button is down repeatedly, and whenever that’s true, we move the ball sprite to the mouse’s X position and 10 plus the mouse’s Y position. We are adding 10 to the Y position to make sure the ball does not go right under the mouse pointer, which would switch it to the “dragging” mode.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/fe8437d9-f7b6-4692-a67a-58bacf15afec.png" alt="6051943d-a046-4689-ac92-d623945b8f8a-image.png" class=" img-responsive img-markdown" width="461" height="339" /></p>
<p dir="auto"> <br />
The ball should follow your mouse whenever you press down and drag the mouse button:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ea091c8a-ff48-4075-900f-eb9db2e4acb9.gif" alt="d1.gif" class=" img-responsive img-markdown" width="484" height="406" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-4-create-clones"></a>Step 4 - Create Clones</h2>
<p dir="auto">We will use many clones of the ball sprite to represent small water drops. We can keep creating new clones after moving the ball:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/78c9d0f8-ff40-4156-8cf0-0858916bfd1e.png" alt="da5017b1-7caf-49f2-92e6-610ea5ae0e16-image.png" class=" img-responsive img-markdown" width="472" height="394" /></p>
<p dir="auto"> <br />
Now we are “drawing” a trail with the clones of the ball:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b706356f-8b0d-4610-afd7-10303c1da234.gif" alt="d3.gif" class=" img-responsive img-markdown" width="484" height="406" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-5-add-physics-bodies-to-each-clone"></a>Step 5 - Add Physics Bodies to Each Clone</h2>
<p dir="auto">Now we are going to hand over these clones to the physics engine, which will help us make the balls behave like real balls. Whenever a new clone is created, we will use the “behave as” block to convert the clone to a circle-shape object:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/2ef23d66-b1e1-4718-8c50-0c10c58cc9ff.png" alt="060e0c3a-866e-4141-9672-4a93e986d4ef-image.png" class=" img-responsive img-markdown" width="619" height="531" /></p>
<p dir="auto"> <br />
Now our clones become “alive”: the physics engine will make them fall due to gravity, and also collide with each other.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a04cb5ee-3a51-4515-81e5-3e0e003f3707.gif" alt="d4.gif" class=" img-responsive img-markdown" width="484" height="406" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-6-hide-the-original-sprite"></a>Step 6 - Hide the Original Sprite</h2>
<p dir="auto">Since we only use clones of this ball sprite to represent water drops, the original sprite is left on the stage at a fixed position:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/43949db2-3932-4706-8a11-7adf662e109f.png" alt="a42708ad-a12f-4f80-b18a-55c267746d69-image.png" class=" img-responsive img-markdown" width="493" height="364" /></p>
<p dir="auto">We can hide the original sprite using the “hide” block, and then “show” the clones after they are created:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/8cf94cb7-3a8e-4c98-bc58-032e199e3e86.png" alt="a73edb8d-22a4-4372-99bd-0ea376c2d1d6-image.png" class=" img-responsive img-markdown" width="646" height="628" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-7-draw-the-bucket-sprite"></a>Step 7 - Draw the Bucket Sprite</h2>
<p dir="auto">Next, let’s create a bucket to hold these “water drops”. Create a new empty sprite named “Bucket”, and draw a bucket using 3 boxes like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/93e0aa53-1f2a-4e22-a1e0-b474fe15f977.gif" alt="bu.gif" class=" img-responsive img-markdown" width="975" height="606" /></p>
<p dir="auto"> <br />
<span style="color:#ec0909">Note that at the end you need to select all boxes, and shift their center to the center of the canvas.</span></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-8-send-a-message-to-create-the-bucket"></a>Step 8 - Send a Message to Create the Bucket</h2>
<p dir="auto">To start the program in the bucket sprite, we should send a message from the “Empty1” sprite. This makes sure we create the bucket AFTER the physics world has been initialized.</p>
<p dir="auto"><span style="color:#e70808">In the “Empty1” sprite</span>, broadcast the “add bucket” message:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/8ad67990-6b15-469a-887a-bfb8f7df4804.png" alt="aa8b319b-f017-435a-9db6-3a661caf211e-image.png" class=" img-responsive img-markdown" width="475" height="482" /></p>
<p dir="auto"> <br />
Then <span style="color:#f41010">in the “Bucket” sprite</span>, receive the message:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/d97dbe1d-1e69-43a6-92f2-79490f980c3f.png" alt="29a9e4b5-ae3b-44cf-b809-c2fc32ff6552-image.png" class=" img-responsive img-markdown" width="339" height="104" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-9-move-the-bucket-to-the-center"></a>Step 9 - Move the Bucket to the Center</h2>
<p dir="auto">In the Bucket sprite, let’s first reset the position and direction of this sprite:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6e79a5fd-a742-47f9-a932-83b6122a3c1a.png" alt="d7e25616-57c1-4909-a327-d462db4959e1-image.png" class=" img-responsive img-markdown" width="348" height="216" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-10-add-a-physics-body-to-the-bucket"></a>Step 10 - Add a Physics Body to the Bucket</h2>
<p dir="auto">Next, we’ll tell the physics engine how we want the bucket to behave in the physics simulation. The bucket is a “concave” shape, since its top edge curves into itself. Therefore, we need to use a compound shape to represent it:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/14668a48-5ed6-4dc8-9afc-9b1990791dc2.png" alt="badf62db-ca34-4147-8bbe-65a03952e4fc-image.png" class=" img-responsive img-markdown" width="1231" height="281" /></p>
<p dir="auto"> <br />
We will set the bucket to be a “movable” object. This is because we don’t need the bucket to fall due to gravity, so it does not need to be “dynamic”. But we do want to rotate it ourselves, so it should not be “fixed” either.</p>
<p dir="auto">Since we set the “debug” parameter to “Yes”, we can see the actual shape created by the physics engine, which is composed of 3 red boxes. This is exactly what we need, so we can set the “debug” parameter back to “No” to hide these red boxes.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/9c8a1334-3547-411f-bd35-91e9e385b2dd.png" alt="8c500417-5c98-4a49-8aa7-c97586c5bad9-image.png" class=" img-responsive img-markdown" width="388" height="243" /></p>
<p dir="auto"> <br />
At this point, our bucket should be able to hold some “water” now:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0d84f103-72a4-4263-9586-366cd89b9d2e.gif" alt="bu1.gif" class=" img-responsive img-markdown" width="489" height="404" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-12-make-the-bucket-rotate"></a>Step 12 - Make the Bucket Rotate</h2>
<p dir="auto">Lastly, to make the animation more interesting, let’s make the bucket rotate around itself.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/e9e7b54b-dc56-4b6b-b34a-8e07c26bedc9.png" alt="33bcac4a-781a-4595-ab6f-1866d1843dab-image.png" class=" img-responsive img-markdown" width="517" height="364" /></p>
<p dir="auto"> <br />
Here is the final result:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b8ca45b4-7ba0-4995-99c8-64a185221fc9.gif" alt="bu5.gif" class=" img-responsive img-markdown" width="489" height="404" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="creative-ideas"></a>Creative Ideas</h2>
<p dir="auto">Please try to create some new animations based on what you learned in this tutorial. Here are some ideas for you to try out:</p>
<ul>
<li>
<p dir="auto">Colored Balls: You can add multiple ball costumes with different colors, and switch the ball’s costume before creating new clones.</p>
</li>
<li>
<p dir="auto">Different Bucket Shapes: You can draw some different shapes for the bucket.</p>
</li>
<li>
<p dir="auto">Make the Bucket Sway Left and Right: Currently the bucket only rotates one way. You can try to make it “sway” side to side, so it does not lose the water drops.</p>
</li>
<li>
<p dir="auto">Update Physics Properties: Try to change the gravity in the physics world and the friction/restitution of the objects. Observe and explain the differences they make.</p>
</li>
</ul>
]]></description><link>https://forum.creaticode.com/topic/816/2d-physics-water-simulator-difficulty-3</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Apr 2026 00:06:20 GMT</lastBuildDate><atom:link href="https://forum.creaticode.com/topic/816.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 21 Feb 2023 16:09:29 GMT</pubDate><ttl>60</ttl></channel></rss>