Hey there! This series of articles will teach you how to use the physics engine in Gandi IDE. You'll get the hang of using the blocks in the physics engine by learning from the best practices.
Welcome to this showcase done using Physics! To observe different effects, simply click the button and push the box with force. You have the flexibility to adjust the force's magnitude and direction, as well as the density and elasticity of the box.
Physics Engine: Collision by @Jamin /Scratch project hosted on Cocrea.
Welcome to play My Project Hosted on Cocrea.world, powered by Gandi IDE.
In this tutorial, I will guide you step by step on how to simulate the collision between two objects using a physics engine.
Step 1: Get the Physics extension installed
To begin, open Gandi IDE and locate the Physics extension in the Extensions.
Click on it to install. Once installed, you can find all blocks in the code area.
Step 2: Add sprites
In order to simulate the collision between two objects, you would need two sprites.
To differentiate them, you can use different colors and shapes. For example, you can draw a green box and a red circle.
Step 3: Set up the physics playground
The method for setting up the physics environment remains the same as in the previous tutorial. You can refer to step 3 in Physics Engine: Gravity & Force.
In this case, we do not want the objects to fall naturally, so we need to set the gravity to 0. The script in the stage area should be as follows:
We position the box sprite on the left side of the stage and enable the physics engine for it.
We position the circle sprite on the right side of the stage and enable the physics engine for it.
Now that the physics environment is set up, we can move on to the next step.
Step 4: Give the small box a little push
You can now try pushing the small box on the left to collide with the circle on the right in the program.
To accomplish this, complete the code in the small box character and set the force direction to 90, which is horizontally to the right.
Click the green flag to give it a try.
Of course, you can also push the circle. Add this code to the circle character, modify the direction to -90, and delete the original code.
Give it another try.
Great job! By completing the above 4 steps, you can successfully simulate the collision effect in Scratch.
Feel free to try it out in Gandi IDE and have fun!
Now go ahead and give it a try in Gandi IDE. You've got this!