Build a high tower made of balls / physics engine

A lot of fun with babylon js and specially with physics engine :smiley:

I am looking how to do tower/building on a empty ground with spheres. This picture shows exactly the situation:

I saw a lot of PGs and docs that explain how to do physics engine, here for example is this the famous one, then I thought to push the spheres to the same position, I guess something like this, but this idea won’t create the shape that I am looking for! Is there any other way to work on it?

Well not sure how it could stand up :slight_smile: Unless you plan to attach them with links?

I am planning to attach the spheres by using range slider, it can be one by one or more, it doesn’t matter.

1 Like

To create a box shape you can simply do something like that:


Oh great! it looks we are close :smiley:
So, to make this box shape I would like to render the action of building by using range slider. Meaning - I start from empty ground and by changing the value of the slider, balls will start to attach each other. The more I move the slider, the more balls will build the box and the opposite when I move back the value of slider, the balls will go away from the box.
Do you have any idea?
PS: I am still newbie

hi i wanna test that too :smiley:

1 Like

that is not close but wanna share :smiley: wired
in progress

Well this is quite simple now given that you have the final tower done:) your slider will just add ball one by one instead of using my 3 loops for x y and z

I think first I should find how to add balls one by one(or can be more), let’s have a look here, I added a loop just running twice the box shape that you created. It looks so ugly, but the way how balls fell down is not bad. Still I am looking how to get the engine starting from empty ground, it means I wanna render only the collision that will build the box.

Could any one help me to render better that example I did 3 loops of creating box shape, by starting the running, the balls move from the ground to up and then fell down again but I would like to have them moving from up to down directly.

Hi @Lokamidou
Each of your createSphere calls, additionally contained a loop of creating 3 spheres, in the same location.
removing that also removes the majority of the bouncing.

Then as i understood, you want them to spawn up high and fall to the ground ?


@aWeirdo Perfect :wink: thank you! So now I can continue by adding a range slider that will update the creation of the shape. Do you have any idea which option is better if I use the Babylon GUI Slider or simply HTML. I checked, there is not a lot of Babylon GUI sliders examples.

Both works…GUI is hardware accelerated and can work in VR

1 Like

i just add some in @aWeirdo sample

Could any of you help me to solve this problem: when I change the value of the slider into the right side I want the tower of the balls increasing into the top. The same way when I change the value of the slider into the left side I want those balls to decrease accordingly.

Here you go…

I may have went a bit overboard… so i hope it’s understandable, but it was fun :sweat_smile:


Top! that looks really amazing :smiley:

I wanted to use the same concept but this time with imported mesh, so I tried with skull.babylon, only “createLayer” is working (function line 56). The dispose function (line 89) dosen’t work. When I apply anything (mesh, box, sphere …) inside the SceneLoader, the dispose function dosen’t work. Should I import first the mesh, and then some how call it or how?

You should only load the model once and then use it to clone new “spheres”

now if you can solve the restitution glitch where you have a bunch of physics imposters stacked in a chain or stacked like that in Deltas scene then you would be an amazing person. Cause right now if you get to many imposters interacting in a row the restitution builds up and builds up till things break.

as you can see by the problem presented by:

Here is one PG showing the restitution problem in full effect.