Dice and lid collision effect issue

Uploading: image.png…

I’m working on a dice game.
Physics rules were applied using cannon.js.
The floor, dices, and lid objects were created using blender.
The three factors below need to be addressed.

  1. The floor moves up and down
  2. The dice bounce up and down
  3. Effect of hitting the lid

I created the floor using the cylinder object in cannon.js. The position value was used to create the effect of the floor moving.

By moving the cylinder (floor) up and down, the effect of bouncing the dice was created.

Problem is number 3 :
Unfortunately, cannonjs does not yet support collisions between trimesh (lid) and box (dice).

If you have any ideas about this part, please help.

I would use a few dozens of invisible plates (drawn yellow in the image) that envelop the glass structure. Thus the dice will bounce off them. Of course, this will not provide perfect collision, but most likely nobody will notice it. There is no need for the plates to cover up the space completely. If there are small gaps, it is OK, since dice cannot slip through them.

Here is a video from one of my courses - a simulation of washing machine. The barrel is made of vertical plates, because the shape is a cylinder:

1 Like

Are you trying to move the trimesh along with the piston cylinder? I would think that static trimesh → cube should work…

You could continue to use the trimesh for your lid, but add a sphere to your existing boxes.
So that it becomes a compound of a box and a sphere.

body = new CANNON.Body({ mass: 1 })
body.addShape(new CANNON.Box(new CANNON.Vec3(0.5, 0.5, 0.5)))
body.addShape(new CANNON.Sphere(0.5))

The dice box shapes will still collide with each other, but the sphere, which sits just within the box, will collide with the lid walls which is a trimesh.

The collision with the lid is not perfect, but you don’t notice it.

Example : Bouncing Dice - Three.js Tutorials



Since we’re sharing dice rolling sims :smiley:


1 Like