Buoyancy Simulation on Scratch

by rohanibarrus in Design > Game Design

17 Views, 0 Favorites, 0 Comments

Buoyancy Simulation on Scratch

Screenshot (8).png

I made a buoyancy simulator on Scratch. It demonstrates the buoyant properties of three different substances: wood, lead, and helium.

The simulation starts by dropping an equal amount of each substance from the same height into a pool of water.

The different substances fall, sink, or float at different speeds.

Supplies

Just a computer with access to scratch

Screenshot (5).png
Screenshot (2).png
Screenshot (4).png

I first had to make the environment in which the simulation takes place. There are three parts in this environment: air, water, and the ground under the water.

The code for the ground and air was pretty simple; it's just telling the desired position.

The code for the water (in the simulation I called it the substance) was similar but I added transparency so it looks more like water and you can see the objects through it.

Screenshot (3).png
Screenshot (6).png
Screenshot (7).png

I then had to make the objects within the simulation which include the wood, lead, and helium.

Each object has its own individual variable for gravity(speed) so they wouldn't get mixed up. After that, I made it so that the speed variable changes as the object falls through different substances. For example, the wood started in the air, so the speed was set to 10 and the wood would change its Y position by: 0 - SPEED (this is important to make sure the object falls down instead of up). Then, when the wood touched the water(substance), the speed would be set to 0 to keep it from sinking (because wood floats). This worked well except for the fact that the wood looked like it just landed on the water as if it were a solid, so I made a custom block and named it "Float"; it animated the wood and made it look like it was bobbing up and down and that made it look a lot better.

The lead is the same concept, except the falling speed through air is 13 and it doesn't float; instead, when it hits water, the Speed is set to 5 and when it hits the ground at the bottom of the water the Speed is set to 0.

Next the helium. It is like the others, except it is missing the Change Y by 0-Speed, so instead it falls upwards at a Speed of 10 through air, and a Speed of 30 through water.

Screenshot (9).png

Next, I just added a second Costume to the helium so when it is under the water it appears as bubbles.

I also made all the objects draggable so you can use the mouse to move them around and drop them from different locations.

And that's that! A simulation of buoyancy on Scratch!