<?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[3D Physics - Smashing Boxes with a Car (Difficulty: 3)]]></title><description><![CDATA[<h2><a class="anchor-offset" name="introduction"></a>Introduction</h2>
<p dir="auto">In this tutorial, you will build a simple game that’s based on physics simulation. The player will drive a car to smash into a stack of boxes, and try to knock away as many boxes as possible.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b16e6b2b-eb36-4090-ae5f-4bd36fa5bc65.gif" width="470" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-1-an-empty-scene-with-physics"></a>Step 1 - An Empty Scene with Physics</h2>
<p dir="auto">To get started, please create a new project on the CreatiCode playground, remove the Sprite1 with the dog, and rename the “Empty1” sprite as “Main”.</p>
<p dir="auto">In the Main sprite, add the following blocks. They will create an empty 3D scene, display the 3D axes, and <a href="/topic/630/enable-physics-for-3d-scenes">enable the physics engine</a> with a gravity of -1000.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1d136eb0-9e56-48d3-b82d-a4e054418db9.png" alt="d2c29e5f-9016-48ef-a2a2-cf14b6deddde-image.png" class=" img-responsive img-markdown" width="485" height="268" /></p>
<p dir="auto"> <br />
This is what you should get:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/dcab15b1-1272-4bd4-bf5c-3694932d2ee3.gif" width="470" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-2-add-a-large-ground"></a>Step 2 - Add a Large Ground</h2>
<p dir="auto">Next, let’s add a large ground using a plane. It will be 4000 units wide and 15000 units long, and you can apply a grid material on it with your favorite colors:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/41a74510-c4d1-4677-bee6-8deb122446a1.png" alt="e80d37fb-6241-4ca2-a8be-555a6dac76b0-image.png" class=" img-responsive img-markdown" width="923" height="327" /></p>
<p dir="auto"> <br />
Here is what it would look like:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f06043c4-3166-4139-a825-a3995d8c95f0.gif" width="480" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-3-enable-physics-for-the-ground"></a>Step 3 - Enable Physics for the Ground</h2>
<p dir="auto">The ground would not move, so its mass should be set to 0. Its restitution and friction are not important for this game. Here is the block for enabling physics for it:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f9c1ab48-452f-4dd3-9139-b0bec4c448a5.png" alt="93574c72-4dbd-44a6-994c-2f5892872c19-image.png" class=" img-responsive img-markdown" width="942" height="63" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-4-add-a-ramp"></a>Step 4 - Add A Ramp</h2>
<p dir="auto">Next, let’s add a ramp for our car. It will be a smaller plane that’s 600 units wide and 1000 units long. Apply any grid material you like. Rotate it by a small angle like 15 degrees around the X-axis, and move it forward so our car will have some room to speed up.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/617a3617-7b38-4a3b-a450-188010db7d74.png" alt="dd18bdff-e712-40bc-9550-3e52f6efbffa-image.png" class=" img-responsive img-markdown" width="908" height="212" /></p>
<p dir="auto"> <br />
Here is what it should look like:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1d83f5db-fe9e-4c6e-8e6b-ec0a5db4a2c2.gif" width="480" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-5-enable-physics-for-the-ramp"></a>Step 5 - Enable Physics for the Ramp</h2>
<p dir="auto">You can use the same physics settings for the ramp as the ground:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f9c1ab48-452f-4dd3-9139-b0bec4c448a5.png" alt="93574c72-4dbd-44a6-994c-2f5892872c19-image.png" class=" img-responsive img-markdown" width="942" height="63" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-6-broadcast-2-messages"></a>Step 6 - Broadcast 2 Messages</h2>
<p dir="auto">By now we have completed building the platform. Next, we’ll need to add the target boxes and the player’s car. To do that, broadcast these 2 messages in the “Main” sprite:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b6c6a32d-7c4b-4873-a109-88fa74ffca87.png" alt="792b76e9-60bd-4cd6-9b5f-31313693ea20-image.png" class=" img-responsive img-markdown" width="712" height="691" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-7-the-targets-sprite"></a>Step 7 - The “Targets” Sprite</h2>
<p dir="auto">To add the target boxes, it’s better to do it in a new sprite. Please add an empty sprite and rename it “Targets”, then receive the “add targets” event in that sprite:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ac13268b-db05-4054-bdac-7ea2976f57df.png" alt="ef1368c6-57de-4dcf-ae21-267b674d75b4-image.png" class=" img-responsive img-markdown" width="331" height="101" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-8-add-the-target-boxes"></a>Step 8 - Add the Target Boxes</h2>
<p dir="auto">To add the target boxes in the “Targets” sprite, we can use 2 new variables “x” and “z”, and use 2 nested for-loops to control these 2 variables. The target boxes should be 100 in size. They should go from x position of -200 to 200, and z position of 50 to 450. They should all be at the same y position of about 5500. Here are the blocks to add these boxes:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c18973d3-7365-4d84-9fe8-88c2c4ff65e8.png" alt="22a1f6ba-fd8d-40cd-b386-6009efdbeb0c-image.png" class=" img-responsive img-markdown" width="786" height="388" /></p>
<p dir="auto"> <br />
They would look like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/d35e75bb-c90e-40a6-b04b-4c836ca90d18.gif" alt="t4.gif" class=" img-responsive img-markdown" width="478" height="351" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-9-add-different-colors"></a>Step 9 - Add Different Colors</h2>
<p dir="auto">To make these boxes look different, we can apply a grid material to each of them with a random color:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/eb78263e-b7bb-4647-9311-c19374f02f85.gif" alt="t5.gif" class=" img-responsive img-markdown" width="951" height="465" /></p>
<p dir="auto"> <br />
Now they look like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/2c168ba3-a017-4888-aa89-71ffead462f8.gif" alt="t6.gif" class=" img-responsive img-markdown" width="471" height="349" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-10-enable-physics-for-target-boxes"></a>Step 10 - Enable Physics for Target Boxes</h2>
<p dir="auto">Lastly, we need to enable physics for each box, so that our car will collide with them. Use a relatively high friction value so that the boxes do not easily slip off:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/e4a9f827-2b52-4c6e-a82b-74f843d9fd40.png" alt="989b35ae-62bb-48b8-a981-98426643c2a8-image.png" class=" img-responsive img-markdown" width="988" height="431" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-11-the-car-sprite"></a>Step 11 - The “Car” Sprite</h2>
<p dir="auto">Now we are ready to add the car. Again, let’s do it in a new sprite named “Car”, and handle the “add car” message there:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1bf752fa-18ae-4264-aee9-282555086902.png" alt="5fded4da-2b43-4103-a30c-45828da549e4-image.png" class=" img-responsive img-markdown" width="256" height="83" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-12-add-a-car-model"></a>Step 12 - Add a Car Model</h2>
<p dir="auto">First, let’s add a car using the “Race Car” model with a height of 50.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ea880d31-edef-4283-9328-6d28e4e29a3d.png" alt="0e648f1b-7d62-494e-a38f-85d8054fa86f-image.png" class=" img-responsive img-markdown" width="1061" height="133" /></p>
<p dir="auto"> <br />
It will look like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/90467349-575f-4b47-ab2a-7f54a2fdef3b.gif" alt="t7.gif" class=" img-responsive img-markdown" width="471" height="349" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-13-enable-car-simulation"></a>Step 13 - Enable Car Simulation</h2>
<p dir="auto">Next, for the most important step of this tutorial, <a href="/topic/750/car-with-physics-simulation">enable car simulation</a> using this block:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/4b83e5e7-0f63-44fd-a13c-f7cde1b7bf9a.png" alt="96f978ca-7576-46a9-8cdc-e5078a3dc2fa-image.png" class=" img-responsive img-markdown" width="1067" height="84" /></p>
<p dir="auto"> <br />
Its mass will be 10 times the mass of each box. A high restitution value will bounce the box away when they are hit by the car. A tire friction of 10% will allow the tire to be a little bit slippery, so when the front wheels are turned, the car body will spin a bit.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-14-add-a-follow-camera"></a>Step 14 - Add a Follow Camera</h2>
<p dir="auto">Now let’s add a camera to follow the car as it runs around. We can use a “Free” direction lock so the player can zoom or turn the camera any time he/she wants to.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/29ceeb4b-bd61-4be5-8271-2bc3a7fc6c50.png" alt="70a19c72-9f3e-42f5-9ee8-c75fd580e757-image.png" class=" img-responsive img-markdown" width="1105" height="250" /></p>
<p dir="auto"> <br />
Here is the new view from the follow camera:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/d1a36efc-f026-4374-b204-277ef19ff203.gif" width="470" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-15-d-and-a-keys-to-steer-the-wheels"></a>Step 15 - “D” and “A” Keys to Steer the Wheels</h2>
<p dir="auto">Now we need to allow the player to drive the car using the keyboard. We will use a forever loop to check for key presses.</p>
<p dir="auto">First, let’s handle the steering angle of the front wheels. When the “D” key is pressed, we should steer the wheels 15 degrees to the right; when the “A” key is pressed, we steer -15 degrees; if neither key is pressed, we set the wheels straight.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1e85ff36-e317-46e2-abf0-5cf063abee0b.png" alt="455f6bde-eaf1-4198-b720-ed05db23c351-image.png" class=" img-responsive img-markdown" width="434" height="679" /></p>
<p dir="auto"> <br />
You can clearly view the front wheels from the bottom of the car:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f771bc3e-08a8-469d-8b72-82047921b5da.gif" width="470" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-16-w-key-to-drive-forward"></a>Step 16 - “W” Key to Drive Forward</h2>
<p dir="auto">Next, we should handle the engine force and braking level, which should be independent of the steering angle.</p>
<p dir="auto">When the “W” key is pressed, we should set a large positive engine force and zero braking:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7746d746-bda5-4039-b739-bf67a6f8bcb1.png" alt="ad61ea86-9577-4205-b638-ab6f5bd126ac-image.png" class=" img-responsive img-markdown" width="532" height="626" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-17-s-key-to-drive-backward"></a>Step 17 - “S” Key to Drive Backward</h2>
<p dir="auto">Similarly, if the “W” key is not pressed, but the “S” key is, then we should set a negative engine force to make the car go backward:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/273385d0-9fb6-4eab-8514-2f9a1b7089e8.png" alt="603e455a-9f70-4518-afed-2ab89adb8e17-image.png" class=" img-responsive img-markdown" width="572" height="402" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-18-space-key-to-apply-brake"></a>Step 18 - “SPACE” Key to Apply Brake</h2>
<p dir="auto">When neither “W” or “S” keys are pressed, and the SPACE key is pressed, we should set a zero engine force, and a braking level of 10%. This way, the car will slow down by 10% repeatedly. If the SPACE key is not pressed either, then we simply set both engine force and braking level to 0.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6646def9-b48b-40f5-9a57-9a4cb0af77f5.png" alt="1dcad26a-890b-4c8a-a45c-db0e995ed900-image.png" class=" img-responsive img-markdown" width="540" height="578" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-19-a-starry-sky"></a>Step 19 - A Starry Sky</h2>
<p dir="auto">Lastly, to make our scene look better, we can set a starry sky in the “Main” sprite, and also hide the 3D axis:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/d6f4a891-ca8e-410a-a413-6c0d04b0524e.png" alt="418ab269-e061-4a55-8571-00eae0dfa100-image.png" class=" img-responsive img-markdown" width="615" height="327" /></p>
<p dir="auto"> <br />
Here is a final demo of the game:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b16e6b2b-eb36-4090-ae5f-4bd36fa5bc65.gif" width="470" style="border-radius:5px;border:1px solid #29622d" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="creative-ideas"></a>Creative Ideas</h2>
<p dir="auto">Here are some suggestions for you to build more interesting games based off this tutorial:</p>
<ul>
<li>Different Targets: you can change the position, shape and count of the targets, and they do not have to be all stacked together.</li>
<li>Different Ramps: you can design the ramp differently, or provide multiple ramps.</li>
<li>Different Goals: you can make the player try to knock all targets off the platform to complete the game</li>
</ul>
]]></description><link>https://forum.creaticode.com/topic/751/3d-physics-smashing-boxes-with-a-car-difficulty-3</link><generator>RSS for Node</generator><lastBuildDate>Fri, 08 May 2026 08:41:49 GMT</lastBuildDate><atom:link href="https://forum.creaticode.com/topic/751.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Dec 2022 04:15:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 3D Physics - Smashing Boxes with a Car (Difficulty: 3) on Fri, 29 Mar 2024 21:02:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.creaticode.com/uid/370">@waseesmabdullahil-0d79d542</a></p>
<p dir="auto">Can you check out this demo project and compare with your code?</p>
<p dir="auto"><a href="https://play.creaticode.com/projects/aba9b9ae5cbc8ab971511a4e" target="_blank">https://play.creaticode.com/projects/aba9b9ae5cbc8ab971511a4e</a><br /> <br />
<iframe src="https://play.creaticode.com/projects/aba9b9ae5cbc8ab971511a4e/embed" width="485" height="402" allowfullscreen></iframe></p>
]]></description><link>https://forum.creaticode.com/post/1378</link><guid isPermaLink="true">https://forum.creaticode.com/post/1378</guid><dc:creator><![CDATA[info-creaticode]]></dc:creator><pubDate>Fri, 29 Mar 2024 21:02:35 GMT</pubDate></item><item><title><![CDATA[Reply to 3D Physics - Smashing Boxes with a Car (Difficulty: 3) on Fri, 29 Mar 2024 19:27:46 GMT]]></title><description><![CDATA[<p dir="auto">my car won’t steer right</p>
]]></description><link>https://forum.creaticode.com/post/1377</link><guid isPermaLink="true">https://forum.creaticode.com/post/1377</guid><dc:creator><![CDATA[waseesmabdullahil-0d79d542]]></dc:creator><pubDate>Fri, 29 Mar 2024 19:27:46 GMT</pubDate></item><item><title><![CDATA[Reply to 3D Physics - Smashing Boxes with a Car (Difficulty: 3) on Fri, 01 Mar 2024 16:47:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.creaticode.com/uid/184">@ttvwyattt-boom-gmail</a> I had this issue also, but I realized that I went ahead too fast and didn’t create a SEPERATE SPRITE for the car and target sprites. Have you done this?</p>
]]></description><link>https://forum.creaticode.com/post/1228</link><guid isPermaLink="true">https://forum.creaticode.com/post/1228</guid><dc:creator><![CDATA[aiden.bedo-45dbf929]]></dc:creator><pubDate>Fri, 01 Mar 2024 16:47:46 GMT</pubDate></item><item><title><![CDATA[Reply to 3D Physics - Smashing Boxes with a Car (Difficulty: 3) on Thu, 04 May 2023 21:32:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.creaticode.com/uid/184">@ttvwyattt-boom-gmail</a></p>
<p dir="auto">Thanks for sharing. There are 2 small adjustments you need to make:</p>
<ol>
<li>
<p dir="auto">The box that sometimes shows up around your car is the last box added to the targets. It happens sometimes that when you add the car, the box has not been moved to its own position in time. To solve this issue, the best solution is to move the code for the targets and the car into 2 new sprites, as suggested in the tutorial steps 7 and 11 above</p>
</li>
<li>
<p dir="auto">The plane can not be too big. The size given in the tutorial has y of 15000, and your project has 150000, which is 10 times larger. Although this seems to be a small difference, the physics engine can not find a solution when you try to drive the car. So try 15000 or some other smaller value. If you do need to have a larger map, you can add more planes, but keep each of them relatively small.</p>
</li>
</ol>
<p dir="auto">Hope that helps!</p>
]]></description><link>https://forum.creaticode.com/post/982</link><guid isPermaLink="true">https://forum.creaticode.com/post/982</guid><dc:creator><![CDATA[info-creaticode]]></dc:creator><pubDate>Thu, 04 May 2023 21:32:22 GMT</pubDate></item><item><title><![CDATA[Reply to 3D Physics - Smashing Boxes with a Car (Difficulty: 3) on Thu, 04 May 2023 19:07:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.creaticode.com/uid/4">@info-creaticode</a> <a href="https://play.creaticode.com/projects/ba803d2ef1090b658877379e" target="_blank">https://play.creaticode.com/projects/ba803d2ef1090b658877379e</a><br /> <br />
<iframe src="https://play.creaticode.com/projects/ba803d2ef1090b658877379e/embed" width="485" height="402" allowfullscreen></iframe></p>
]]></description><link>https://forum.creaticode.com/post/981</link><guid isPermaLink="true">https://forum.creaticode.com/post/981</guid><dc:creator><![CDATA[ttvwyattt.boom-gmail]]></dc:creator><pubDate>Thu, 04 May 2023 19:07:05 GMT</pubDate></item><item><title><![CDATA[Reply to 3D Physics - Smashing Boxes with a Car (Difficulty: 3) on Fri, 28 Apr 2023 18:37:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.creaticode.com/uid/184">@ttvwyattt-boom-gmail</a></p>
<p dir="auto">Hi there, please share your project and post the URL here so that we can help review what’s the issue.</p>
<p dir="auto">CreatiCode</p>
]]></description><link>https://forum.creaticode.com/post/979</link><guid isPermaLink="true">https://forum.creaticode.com/post/979</guid><dc:creator><![CDATA[info-creaticode]]></dc:creator><pubDate>Fri, 28 Apr 2023 18:37:40 GMT</pubDate></item><item><title><![CDATA[Reply to 3D Physics - Smashing Boxes with a Car (Difficulty: 3) on Fri, 28 Apr 2023 17:53:00 GMT]]></title><description><![CDATA[<p dir="auto">this does not work. one of the boxes follow the car and I have not yet found a way to get rid of it.</p>
]]></description><link>https://forum.creaticode.com/post/978</link><guid isPermaLink="true">https://forum.creaticode.com/post/978</guid><dc:creator><![CDATA[ttvwyattt.boom-gmail]]></dc:creator><pubDate>Fri, 28 Apr 2023 17:53:00 GMT</pubDate></item></channel></rss>