Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. Tutorials
  4. 3D Physics - Water Simulator (Difficulty: 2)

3D Physics - Water Simulator (Difficulty: 2)

Scheduled Pinned Locked Moved Tutorials
1 Posts 1 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

     

    In this tutorial, you will learn to use the 3D physics engine to control many water drops (spheres) for a fun animation. The 3D physics engine will manage the movement of 3D objects for us, which allows us to easily create complex 3D simulations with only a few blocks of code.

    ball.gif

     
     

    Step 1 - Initialize 3D Scene with Physics Engine

     

    Please create a new project, remove the dog sprite, and add these blocks to initialize the 3D scene, 3D axis and the 3D physics engine.

    d4959c3b-bb21-4e0a-ad78-3b1ab224908a-image.png

     
    Note that the gravity is set to -600, which makes objects move down (negative Z direction).

     
     

    Step 2 - Add a static ground

     

    We will start with a large, flat box to serve as the ground. To make sure it will not move or fall, we just need to set its mass to 0.

    e7c874ad-a130-40d1-97c2-8fd7b12856e4-image.png

     
     

    Step 3 - Add a bucket using as a rectangular cube

     

    Next, let’s add a bucket to hold the balls. The “rectangular tube” shape is very convenient for this purpose. It is essentially a box, but you can change the cap type to “bottom”, so it is open on top.

    aff2fb8d-bef7-4f1e-8db5-6c8f6fb07b0c-image.png

     
    Notes:

    • We need to move it up by 200 to be above the ground.
    • You can apply any texture to it.
    • We set its mass to be a large number like 10000, so it won’t be affected by the balls falling into it.
    • Its restitution is 100%, so the balls will rebound when they hit the bottom or sides of this bucket.

     
     

    Step 4 - Make the bucket spin

     

    Since the bucket is controlled by the 3D physics engine, we can’t spin it using the “set speed” block. Instead, we need to use a special block in the “3D Physics” category to set the rotation speed around the Z axis:

    2be82703-986a-4eef-944e-e62c47136313-image.png

     
     

    Step 5 - Add a new sphere when SPACE key is pressed

     

    To make the animation look cool, we will give each sphere a random color, which means their color/saturation/brightness are all random numbers. To keep the colors bright, we will set the range for brightness between 50 and 100.

    c0bc86fd-0b30-4318-958c-a696105f4b80-image.png

     
     

    Step 6 - Move the sphere to a random position

     

    Next, we will move the new sphere to a random position, which means its x/y/z positions are all random.

    939583df-734d-4adc-98dd-77923b3afe4e-image.png

     
     

    Step 7 - Add a physics body

     

    Lastly, we will hand over control of the ball to the 3D physics engine by attaching a “sphere” shape body to it. We will give it a very small mass so it won’t affect the movement of the bucket. Also, we will set it to 100% restitution, so it will bounce against other balls and the bucket.

    f1dc262a-5681-4c71-8aba-c3ea8a0e053a-image.png

     
     

    Challenges

     

    This project is very basic. You can challenge yourself with some of the following tasks:

    • Add objects of different shapes and sizes
    • Create a more complex container other than the bucket. For example, you can try to create a compound shape that is made of many boxes.
    • Change the container to platforms: you can use many boxes to serve as platforms that are placed from top to bottom, so the balls will bounce from one platform to another like marbles.
    1 Reply Last reply
    0
    • CreatiCodeI CreatiCode pinned this topic on

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode