Hi, I’ve been playing with the various polyhedra that are out there and they are amazing. The MeshCollider works out of the box with all predefined shapes.
One of the shapes that was missing for me was a variant of the pentagonal dipyramid, so I took a stab at implementing that myself with custom vertex info.
It looks as what I want, but the MeshCollider behaves very odd on the shape, so I feel like I’m missing something.
This is my playground example: Babylon.js Playground
The d12 and d20 work as expected, but the d10 bounces in a very strange fashion. Also when I give no angular velocity it just stays on its point instead of rolling over.
Hey @Kruptein. Haven’t done any physics with BabylonJS yet, but you got me curious so took a quick look at your code. Couldn’t see anything obvious so modified values to get bit more predicable behaviour, thinking it might be easy to see what’s going on.
From what I can tell, it seems that weight is not distributed correctly during simulation. Is there a way you can change the centre of gravity somehow? It looks like it is currently at the tip of the mesh, which perhaps would explain weird turbulence from your first example.
Well one thing I did notice in the meanwhile, is that if I go to the inspector and enable ‘physics’.
The wireframe is completely off for all shapes, so maybe I’m doing something wrong there as well.
Not sure if I am helping with this but see the object center in the alert. https://playground.babylonjs.com/#NQXR4F#4
Yeah that doesn’t seem right…
Perhaps a material issue. Check this out.
It looks much better but for sure there is problem how forces are applied. It seems like the tip of the dice is like 100x heavier than the rest of the dice.
I would try to focus on fixing that center of the object. Shouldn’t that be (0,0,0) in local object space?
The physics debug wireframe thingy is also completely off for the d20, so unsure if I need to first do a certain operation on the meshcollider as well to “sync” it with the base mesh
Hey all help is appreciated!
Adding @Cedric as this seems to be a physics problem: the mesh looks ok to me, normals are ok. I tried to set
flat: false when creating the shape to have smooth normals but it does not fix the problem.
Use a convex hull as it applies particularly well with the dice mesh. Then, center your vertex position around 0 so forces distribution will work better (and transform will be at the center of the mesh). And that’s it!
dice test | Babylon.js Playground
@Kruptein Have you seen this playground demo?
Came across it trying to fix something in my project, It doesn’t help me but instantly thought of your thread. Demo uses
Polyhedron/polyhedra.js from babylon extensions. Perhaps it has “dice” you can use.
Hey thanks for the recommendation, but I had already found that page yeah sadly the shape I want isn’t in there