Spheres moving through a frictionless environment

I want to create spheres moving through a frictionless environment with gravity(cube). But I don’t know how to make the spheres appear inside the cube. They appear outside and if I add physical properties to the spheres, they just fall down the screen and disappear. Can anybody give me an advice on how what I can do to make the spheres stay inside the cube…

Thanks in advanced

set the gravity of the physics space to zero (before you add the objects)


1 Like

I tried that already and the sphere doesn’t move anymore, but when I add physical properties to the cube, it seem like they collide with each other, the cube goes down and the sphere goes up. This also means that the sphere is outside the cube, and I want the sphere to be inside the cube moving through… so how can I accomplish that?

Do you want them to collide with the cube at all? If not then just don’t add it to the physics stuff at all.

If so then you will need to explain more clearly.

1 Like

The spheres should be moving through the cube and respond to collisions. For example if a sphere collides with the walls of the cube it should change direction and keep moving. When I run my code, the spheres seems to be inside the cube but when they move they pass through the plane(surfaces of the cube) and keep moving until they disappear from the screen, and I don’t know how to keep them inside the cube.

Actually i assume that you cannot spawn physical object inside another physical objects, at least when i did that by accident the lighter object did get a heavy force applied.

You have to build your own cube of 6 planes.

Afaik you need to set the mass of the cube to 0, trought this it gets used as a static object. The spheres of course need a mass. (I assume here you are using rigidbodys?)

Since i am still not very experienced with bullet, please correct me if i am wrong.

1 Like

The basic shapes are solid, yeah. Immovable Mesh shapes are hollow though.

1 Like

A cube conceptually is a solid filled block. In order to change that you will need to model a room - which means either 6 planes or 6 cubes to form the walls/floor/ceiling.

1 Like

If the spheres are inside the cube, have you flipped the normals of the cube? If the normals are pointing outwards and the spheres are on the inside, then it will let them out, and then not let them in again. (I’m assuming Bullet works like that)

1 Like

There is no normals in bullet. Again, basic shapes are solid, meshes are hollow. So use a mesh if you don’t move the box.

1 Like

The following code creates a box:

Box box = new Box(new Vector3f(1,-1,1),1,1,1);

Geometry cube = new Geometry (“Box”, box);

Material mat = new Material(assetManager, “common/





Can I spawn spheres inside this cube? and make

them move inside coliding with the walls without getting out.

If I can, how do I do it?

Thanks to everybody for their help.

You are using a basic shape which is solid.

Even though it says box its actually like a brick (in JME3), think now… can you put spheres inside a brick?

Perhaps you could import a cube from blender, or as suggested by zarch build a room for yourself by using planes.



@normen said:
The basic shapes are solid, yeah. Immovable Mesh shapes are hollow though.

Is this what you mean by creating a hollow box?
Mesh box = new Box(new Vector3f(0,0,0),1,1,1);
cube = new Geometry("Box", box);
Material mat1 = new Material(assetManager,
mat1.setColor("Color", ColorRGBA.Green);


no, we’re talking about physics