<?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 - game for drone dropping a box (Difficulty: 4)]]></title><description><![CDATA[<h2><a class="anchor-offset" name="introduction"></a>Introduction</h2>
<p dir="auto"> </p>
<p dir="auto">In a <a href="https://www.forum.creaticode.com/topic/323/3d-a-flying-drone-difficulty-1" target="_blank" rel="noopener noreferrer nofollow ugc">previous tutorial</a>, you learned how to simulate a drone flying through a city. However, to keep it simple, no physics simulation was used.</p>
<p dir="auto">In this tutorial, you will learn to simulate a drone carrying a box using the 3D physics engine. You will need to apply forces and impulses to the drone to fly it to the destination, and also use a physics constraint to attach a box to the drone.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone7.gif" alt="drone7.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-1-create-a-new-project"></a>Step 1 - Create a New Project</h2>
<p dir="auto"> </p>
<p dir="auto">Please create a new project in the CreatiCode playground, and remove the “Sprite1”. We will only need the “Empty1” sprite for this project.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-2-initialize-the-3d-scene-and-physics-engine"></a>Step 2 - Initialize the 3D scene and physics engine</h2>
<p dir="auto"> </p>
<p dir="auto">All 3D projects should start with initializing the 3D scene, and we will just use an “Empty” scene for this project. Since we will use the physisc engine, it should be initialized right away as well:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/82ebe022-0372-497b-86df-453fa66192ed.png" alt="92ad0691-a064-4be4-a60b-1cac63d59ddc-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Note that to make things drop fast in this simulation, we will use a gravity of -1000.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-3-define-2-new-custom-blocks"></a>Step 3 - Define 2 new custom blocks</h2>
<p dir="auto"> </p>
<p dir="auto">To keep our blocks organized, let’s create 2 new custom blocks:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ff73895c-1713-40e9-b338-ab298b4d9760.png" alt="e66fce9a-6702-44eb-90e2-be3266024a81-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-4-add-a-static-ground"></a>Step 4 - Add a static ground</h2>
<p dir="auto"> </p>
<p dir="auto">In the “setup scene” block’s definition, we first need to add a large ground, so objects do not fall endlessly. We can use a large and thin 3D box for the ground, with a size of 20000 by 20000, and a thickness of 1. We will give it a grid material so that it is easy to see object movements. We also need to give the ground a physics body with a mass of 0, which makes it static (won’t fall).</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6d5a403b-5653-492e-93b7-e772d2c4a188.png" alt="ad7bf09e-a4e9-4638-b28d-76bb40a78c8f-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
The ground will look like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/550cfa4d-53f9-40fc-846a-82eed6559089.png" alt="9510bf87-24ac-4a5a-a668-d72ac238cf89-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-5-add-a-basket"></a>Step 5 - Add a basket</h2>
<p dir="auto"> </p>
<p dir="auto">Next, we will add a basket so we can drop the box into it. The “rectangle tube” is a perfect shape for this purpose, and there is a corresponding body shape of “rectangle tube” as well.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ef332207-e045-471e-954e-58bb4975cec0.png" alt="33410f88-ccde-46d7-8b30-570d741e6153-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
You can place this basket at any position. For this example, we will put it at x of 400 and y of 1200, which will be at the front right direction from the camera view. We will also need to set its z position to be 75 or higher, so it is above the ground:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b454d5e1-9521-4968-8103-081ddff7e5cb.png" alt="38833da8-5364-432c-972f-fc18b2a66dce-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-6-add-a-wall"></a>Step 6 - Add a wall</h2>
<p dir="auto"> </p>
<p dir="auto">As an optional step, we can add a wall to block the drone. It can be a simple box right in front of the camera:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/eca15818-004b-413b-bc86-26efcbe04d07.png" alt="9cd57428-3f90-43c7-afca-391ce74653c3-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Again, make sure its z position is half of its height, so the entire box is above the ground. The scene will look like this now:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/084a57a1-ee53-427b-906d-fe7b9de1db1d.png" alt="6fb66cc3-c978-4727-8d3a-24516a905b0d-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-7-add-the-drone"></a>Step 7 - Add the drone</h2>
<p dir="auto"> </p>
<p dir="auto">Next, we work on the “add drone” block.</p>
<p dir="auto">First, we will add a drone, and move it above the ground:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/dbdf4223-3d57-43b1-860d-0fa6f881cef7.png" alt="388fa016-127f-4d3f-9e3d-2f4a0993db68-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-8-enable-physics-for-the-drone"></a>Step 8 - Enable physics for the drone</h2>
<p dir="auto"> </p>
<p dir="auto">Next, we will assign a physics body to the drone so it is controlled by the physics engine. Its mass will be 100, so it will fall due to gravity. Also, to prevent the drone from tilting forward or sideways, we will not allow it to rotate around any of the 3 axes:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/08a53e05-c190-4971-8c7b-0dc8528ac5ec.png" alt="3e188274-ac13-4196-ac01-3dd4b368cdd4-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
When we run the program, the drone should fall to the ground like this due to gravity:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone1.gif" alt="drone1.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-9-add-a-follow-camera"></a>Step 9 - Add a follow camera</h2>
<p dir="auto"> </p>
<p dir="auto">Since the drone will be flying around, we will use a follow camera that will follow the drone. We can add the camera right after adding the drone:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/55d799de-2c51-4da4-9ca1-53e66388104c.png" alt="77d54d94-8b99-4554-a7e4-068c848b6ac1-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
In this example, the camera will be 1500 units away from the drone, and looking down at an angle of 45 degrees. It will move as the drone falls down. The user can still drag the left mouse button to view it from different angles:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone2.gif" alt="drone2.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-10-add-a-gift-box"></a>Step 10 - Add a gift box</h2>
<p dir="auto"> </p>
<p dir="auto">Next, we will add a gift box object right below the drone. We will set its height to 100, but also offset its origin by 50 in the z direction, which ensures its position is anchored at the center of its body instead of its bottom. Note that we only need to add this offset for models added using “add model”, and you can refer to <a href="https://www.forum.creaticode.com/topic/640/adding-physics-bodies-for-3d-objects" target="_blank" rel="noopener noreferrer nofollow ugc">this article</a> for more information.</p>
<p dir="auto">The gift box will also have a box-shaped physics body with a mass of 100. We will set its z position to 50, which is precisely half of its height so that it will rest on the ground.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/89beed03-9329-4c07-9da7-227f05aabd2a.png" alt="49260dd9-2c5d-47b0-9397-d14faa0d1104-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Now the drone will fall onto the gift box and stay there, since both of their bodies are approximated using simple boxes:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone3.gif" alt="drone3.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-11-link-the-drone-and-the-gift-box"></a>Step 11 - Link the drone and the gift box</h2>
<p dir="auto"> </p>
<p dir="auto">To simulate the drone picking up the gift box, we will add a “fixed constraint” between them. This constraint will try to make sure these 2 objects stay at the same relative positions. So when we move the drone, the gift box will be moved as well, as if it is picked up by the drone.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/05e183b8-74ab-47ca-bf50-fdaecc81679a.png" alt="a9d31fad-3d4d-432e-8538-2b346c762bce-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
Note that we are naming this constraint as “link”, which can be used to remove it later.</p>
<p dir="auto">By now, we have finished setting up all the objects. Next, we will allow the player to use different keys to control the drone.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-12-turn-on-the-drone"></a>Step 12 - “Turn on” the drone</h2>
<p dir="auto"> </p>
<p dir="auto">When we play with a real drone, the first step is to turn it on, which starts the propellers. The goal is to apply an upward force to the drone to cancel out gravity. The drone may not fly higher yet, but it will be much easier to make it fly later.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialturnondrone.gif" alt="tutorialturnondrone.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
To do that, we will need to apply a force in the z direction when the “L” key is pressed:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b2d731d5-5413-401e-ba7d-57e30405c537.png" alt="62afffb7-21a6-4ba3-84bb-f1d9c9030bb9-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
The strength of this force should match that of gravity. Since gravity is -1000 and the mass of the drone and the gift box is 200 in total, we need an upward force of 200000 to cancel out the gravity force.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-13-change-the-drone-s-color"></a>Step 13 - Change the drone’s color</h2>
<p dir="auto"> </p>
<p dir="auto">Since this drone model does not support animating the spinning propellers, we need another way to tell the player that the drone has been “turned on” and gravity is canceled out. For example, we can change its color to green like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/aaffdc92-5bea-4321-bd0b-e265878f9ba7.png" alt="83025f39-d4ba-44b6-91d0-e1d834d9b0d8-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-14-make-the-drone-rise"></a>Step 14 - Make the drone rise</h2>
<p dir="auto"> </p>
<p dir="auto">Whenever the player presses the “J” key, we will give the drone a one-time push (an impulse) so it gains a rising speed. It will maintain this speed, since there is no gravity (it is canceled out). If the player presses the J key more times, then the rising speed will be faster.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/545d11a1-906a-4b3b-b331-e6add543ab2d.png" alt="a3f9eaa5-ed16-4090-bdf1-61d3678b9a79-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
The size of this impulse determines how much rising speed the drone gains. Feel free to try different values. You can try to make the drone rise now: press “L” once first, then press “J” one or multiple times.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone4.gif" alt="drone4.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-15-make-the-drone-fall-or-slow-down"></a>Step 15 - Make the drone fall or slow down</h2>
<p dir="auto"> </p>
<p dir="auto">Similarly, when the player presses the “K” key, we will apply a downward impulse of the same size. This will make the drone stay in the air or even fall, depending on how many times the player presses the “K” key:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/32512a0f-fa15-4444-ae78-c70c170c4099.png" alt="ae9e7f43-3b38-4bee-a5e8-6da349c685d3-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
If we press the J key once and then the K key once, then the drone will stay floating in the air:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone5.gif" alt="drone5.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-16-drop-the-gift-box"></a>Step 16 - Drop the gift box</h2>
<p dir="auto"> </p>
<p dir="auto">To simulate dropping the gift box, we just need to remove the constraint between them. Let’s trigger that with the “SPACE” key:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7f799e17-3dc4-4bba-9f8d-9e71f9d0e4d0.png" alt="17fad5f3-19cd-420d-b2e6-4dfbdc8ffda5-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> </p>
<p dir="auto">We can test the program this way: we press the “L” key to turn on the drone, press “J” to make it rise, then press “K” to make it stay there. Then when we press “SPACE”, the gift box will start to fall to the ground, since it is no longer tied to the drone. However, something interesting will also happen: the drone itself will start to rise rapidly. Can you guess why?</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone6.gif" alt="drone6.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-17-reduce-the-propeller-force"></a>Step 17 - Reduce the propeller force</h2>
<p dir="auto"> </p>
<p dir="auto">The reason is that we are applying an upward force of 200000 to the drone, which balances out the gravity on both the drone and the gift box. When the gift box is detached, the gravity force will reduce to half of that (1000 * 100), so the upward force is too strong.</p>
<p dir="auto">To avoid this issue, we need to reduce the upward force by 1000000 like this:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6d058507-1e50-45e2-8707-dc5fcc60dcef.png" alt="0bfecfcd-f36a-4dc2-9b82-294beb7e6d42-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
This will keep the upward force in balance with the gravity force, so the drone will still stay in the air without being pushed higher or lower.</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-18-make-the-drone-go-forward"></a>Step 18 - Make the drone go forward</h2>
<p dir="auto"> </p>
<p dir="auto">For the last part of the game, we need to add key controls for the player to move the drone toward the basket. We will start with the “W” key, which will give the drone a forward speed along the Y axis:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/d4c462a2-63e0-4e51-b232-6fecdeeb0103.png" alt="1ec05a92-faad-4e7c-b17e-169e579369c3-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-19-make-the-drone-go-backward"></a>Step 19 - Make the drone go backward</h2>
<p dir="auto"> </p>
<p dir="auto">Similarly, when the player presses the “S” key, we will apply a one-time push backward, along the negative Y direction. This will make the drone stop moving forward or even move backward:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/410cd83a-f206-477f-9c13-555aa7ef1c0b.png" alt="c1e0b10c-0680-4aed-a236-f8f7e2952f54-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="step-20-moving-left-and-right"></a>Step 20 - Moving left and right</h2>
<p dir="auto"> </p>
<p dir="auto">Lastly, we will use the “A” and “D” keys for moving left and right:</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/de70cc82-35cd-42b2-98b2-ef56411fad8c.png" alt="62ef10e0-7950-4177-8926-3fe2321c025e-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
By now, the game is playable. The player has to fly the drone towards the basket and then drop the giftbox into the basket. Note that when the player press the “SPACE” key a second time, the upward force will be fully cleared out, so the drone will fall to the ground.</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/tutorialdrone7.gif" alt="drone7.gif" class=" img-fluid img-markdown" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="further-enhancements"></a>Further Enhancements</h2>
<p dir="auto"> </p>
<p dir="auto">This program only illustrates the basics of how to use the 3D physics engine and impulses/forces. Here are some ideas for you to enhance it as practice:</p>
<ul>
<li><strong>Stop moving</strong>: you can add a new key for the player to stop the drone in both directions. You will need to keep track of the impulses applied to the drone so far, and then apply impulses in the opposite directions.</li>
<li><strong>Pick up the gift box</strong>: Instead of starting the program with the gift box attached to the drone, you can place the gift box at a different position, and make the player fly the drone to the pick up the gift box first, then drop it off at the basket.</li>
<li><strong>Return home</strong>: when the “H” key is pressed, the drone will fly back towards the origin point automatically and land there</li>
<li><strong>Add Rotation</strong>: instead of using WASD to move forward or sideways, we can also allow the player to turn the drone left or right, then move it forward or backward. You can use this block to rotate the drone around the Z axis: set physics body rotation speed around xyz axes. To find out the drone’s current direction, you can use this block: get physics body [Rotation z v]. Once you have the current facing direction, you can use that to calculate the x and y values used in the “apply impulse” block to make the drone go forward or backward along the current facing direction.</li>
<li><strong>Add Propeller Animations</strong>: You can use a drone model without the propellers, then add 4 propeller objects as its children. Then you can simulate the spinning propellers. Here is a small example:</li>
</ul>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/813d5ec8-cd3f-4921-818a-1a0c4ea6f3ac.png" alt="2527938c-5e3c-4842-9295-515d210eb956-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.creaticode.com/topic/1874/3d-physics-game-for-drone-dropping-a-box-difficulty-4</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Jul 2026 20:08:42 GMT</lastBuildDate><atom:link href="https://forum.creaticode.com/topic/1874.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Mar 2025 22:00:45 GMT</pubDate><ttl>60</ttl></channel></rss>