There is a question related to physics. Suppose I have some platforms from which the sphere bounces. Platforms can spin along the Y axis. If the sphere touches the flat surface of the platform, then I give it an impulse to bounce. Every time the sphere touches the platform. But once the sphere is in contact with the edge of the platform or the corner, then it is given too much momentum which pushes the sphere very high. The same effect is observed if during the passage of the sphere into the hole, start turning the platform.
In contact with the sphere - it begins to shake (the sphere). There is also a moment when the sphere, having gained speed, flies through the platforms.
The sphere can move only along the Y axis.
As physic engine used ammo.js
The scope is declared as follows:
Game.Ball = TModels.generateBall ();
Game.Ball.physicsImpostor = new BABYLON.PhysicsImpostor (Game.Ball, BABYLON.PhysicsImpostor.SphereImpostor, {mass: 0.1});
Game.Ball.physicsImpostor.physicsBody.setAngularFactor (new Ammo.btVector3 (0, 0, 0));
Game.Ball.physicsImpostor.physicsBody.setLinearFactor (new Ammo.btVector3 (0, 1, 0));
The platform is declared as follows:
disc.checkCollisions = true;
disc.physicsImpostor = new BABYLON.PhysicsImpostor (disc, BABYLON.PhysicsImpostor.MeshImpostor, {mass: 0});
disc.physicsImpostor.registerOnPhysicsCollide (Game.Ball.physicsImpostor, function (main, collided) {
Game.Ball.physicsImpostor.applyImpulse (new BABYLON.Vector3 (0, 0.3, 0), Game.Ball.getAbsolutePosition ());
....
Could you put a console.log before the apply impulse for debugging? I think the registerOnPhysicsCollide function might be called multiple times if the ball lands on an edge.
If it indeed is called twice, giving your ball a BoxImpostor instead of a sphere one might help in your case.
This might be a bug in _isImpostorInContact of the ammoJSPlugin. registerOnPhysicsCollide depends on that function. Yesterday (even though its private) I experiemented a bit with _isImpostorInContact to check whether I can use it for detecting if my player isGrounded. I got pretty random results from that function. With one collider I always got a collision no matter what. With another collider I got a collision once on startup and then no more.
Ammo provides 2 functions that i could find world.contactPairTest and world.contactTest, contactPairTest fired way too many events so I only fire an event when both contactPairTest and contactTest are true but I guess there are still issues.
Сan i manually animate the falling and rebounding of the sphere? how best to do it? Initially, I wanted to go along this path, since physics was actually useless. But faced with the fact that the sphere did not want to fly through the empty spaces in the platforms.
I already did some testing with the Manifold method yesterday. But it returns an object like: {J:123456} as physicsBody that is related in a collision. Simple reference checking or checking the equality of the number didn’t work to get the associated babylon meshes from that. I guess that is somekind of emscripten special object?
The also say:
Be careful when using contact callbacks: They may be called too frequently for your purposes.
That might be related to your experience. Sadly they don’t provide any explanations on why that is the case