Logo
  • Features
  • Educators
  • What's New
  • Blog
  • Showcase
  • About us
  • Contact
Try it now!
Physics Engine: Move & Rotation
📍

Physics Engine: Move & Rotation

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 right or left button to move the box. You can make the scroll roll by triggering the mechanism. You have the flexibility to adjust the speed of the box, the roughness of the ground, as well as the torque and direction of the scroll.

Physics Engine: Move & Rotation by @Jamin /Scratch project hosted on Cocrea.

Welcome to play My Project Hosted on Cocrea.world, powered by Gandi IDE.

cocrea.world

Physics Engine: Move & Rotation by @Jamin /Scratch project hosted on Cocrea.

In this tutorial, I will guide you step by step on how to simulate movement and rotation 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 movement and rotation, you would need two sprites.

The first Sprite is used to simulate the moving effect, so it is better to use the familiar box.

image

The other one is used for the rotating effect. You can try drawing a sprite in the shape shown in the picture, or draw any shape you like.

image

It is important to note that when the sprite rotates, it rotates around its own center of shape, so you need to set the position of the center of shape properly.

image

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, I want the box to move on the ground, so I setup the stage to a boxed stage.

The script in the stage area should be as follows:

image

Set the initial position of the box to (0,-100) and enable the physics engine for it.

image

We position the sprite for rotation at the center of the stage and enable the physics engine for it. I hope this sprite can rotate in a fixed position. You can use this block to fix the sprite in its position.

image

To see the effects of each option in this block, you can refer to the documentation of the Physics extension.

The script in this sprite should be as follows:

image

Now that the physics environment is set up, we can move on to the next step.

Step 4: Move the little box

I want to use arrow key to move the box in right or left direction.

To accomplish this, you can use this block to set the speed of the box.

image

Scripts in the box sprite should be:

image
image

Click the green flag to give it a try.

Step 5: Rotate the sprite

I want the sprite to rotate when I click on it.

You can use this block to spin a sprite.

image

The script in the sprite should be:

image

Click the green flag to give it a try.

Great job! By completing the above 5 steps, you can successfully simulate the movement and rotation 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!

>>> Gandi IDE

💡
If you have any questions or suggestions, you can find us in the discord channel: https://discord.gg/U3nyveCvRa
Logo

Designed by 2ndR with love

Discord