Another weird physics observation

The following scene should be simple.
A sphere on a (CSG) plane.
The sphere is applied with a force in z-direction.
The sphere should but does not follow a straight line.

See here:

Please start it a few times. The sphere always uses a slightly different route and never a straight route.

If you change the if-clause to false then no CSG is used and in that case the sphere takes a straight route.

How to achieve the same with a CSG?

adding @Cedric

I tried debugging, but have not yet found the issue, though found something strange:

I tried postponing applyForce in setTimeout, but doing so causes the ball to move much faster…

setTimeout(() => {
    sphere.physicsImpostor.applyForce(forceDirection.scale(28), sphere.getAbsolutePosition());
}, 100);

Edited Playground:

I also tried running the below before creating the PhysicsImpostor's


but this did not seem to solve the issue when using CSG

Unfortunately, this issue is linked to the physics engine. Between determinism, number precision, implementation, … you will have to tweak your values to make it behave the way you want.

For example, I’ve seen that if the cylinder has too many side, more triangles are generated by the CSG and Cannon computes ‘ghost’ collisions near the hole. With fewer sides and with a lower restitution value, the ball follows a more straight trajectory.

Ball with hole | Babylon.js Playground

So, no magic here. Test, tweak improve. It will be the same with other engines. I generally have more trust in ammojs because it’s been used in VFX and has a broader adoption.

I extended my example now with a line to show the wireframe:

For the ball the wireframe lines are little hurdles as it seems.Most probably the height slightly differs.