[SOLVED] Ammo.js not returning collision callbacks

Would it be possible to post a link to the project please? It looks like you aren’t doing anything out of the ordinary :thinking:

Sure. I prepared my test scene too. Just hit play and you will be able to test it without opening additional tabs. Sometimes the ball will work just fine, sometimes not.

https://playcanvas.com/project/548909/overview/pongmmo

Thank you!

It looks like it is a case of the ball going fast enough to go through/pass the wall in my repo.

I made the wall’s half extent Z 100 and it worked fine after that.

Bearing in mind that this is a 3D physics sim, the Z depth may have been too small to be registered as a collision.

You may also need to look at enabling CCD for the ball for higher speeds on slower PCs https://developer.playcanvas.com/en/tutorials/physics-with-ccd/

1 Like

Thank you very much!

Actually I noticed that the issue is still not fixed with bigger half extent and CCD on. I opened 2 different tabs to simulate a multiplayer game and it still has issues :confused:

What speeds is the ball going at when that happens? Large timesteps can cause issues as well. Is the sweep radius relative to the ball size?

You may also want to decrease the scale somewhat. IIRC, the ball is 25m. If you bring it back down to football size levels, that might help.

The alternative is to forgo the physics and implement your own.

I will try to downsize everything by the right scale so the ball will be 1m (or even smaller)

That would also mean to adjust velocity at a smaller size.

As for CCD, I might have configured wrong as I left motionTreshold at 1.

I will let you know how downsizing everything went.

Sorry for the late reply. Downsizing everything greatly improved performance. I think I still have the issues to understand how to configure CCD. For swept sphere radius is simple since my ball is a 1x1x1 cube and the sphere radius is set to default 1.

Now…how do I accurately set Motion Threshold? And, if my velocity keeps changing, is there a way I need to update it? 0.1 Motion Threshold seems to work best with 14 Velocity in my case but around 28 velocity it starts to go back to the older issues.

Thank you again.

Sphere radius should be bigger than the collision mesh. Think of it as an enlarged collision area as a ‘broad stroke’.

Motion threshold is the minimum velocity for when to use the enlarged collision volume.

Good to know. The description of Sphere Radius says the opposite: 'This should be below the half extent of the collision volume. E.g For an object of dimensions 1 meter, try 0.2'

Thank you very much!

Oh, whoops! My memory is a little fuzzy then! Go with what you read, I was running from memory when I replied :sweat_smile:

I will go with sphere radius of 1. 0.2 doesn’t work properly for me but 1 is just fine. :stuck_out_tongue:

Hello.
I have the same problem.
I am using the “setLinearVelocity” method with high speeds.
The object is overcoming the obstacle.
I fixed the stepSimulation method with parameters (0.01, 0)
but it still doesn’t work.
when I slow down the collision works.

@Mario_Lopes Did you read this:

https://developer.playcanvas.com/en/user-manual/physics/calling-ammo/#continuous-collision-detection

I solved the problem by increasing the 3rd “fixedTimeStep” parameter of the “stepSimulation” method. thank you will.

BTW, enabling the CCD doesn’t solve the problem with collision detection completely. Just imagine we have a fast moving body (like bullet) with moves towards a wall. When bullet’s speed becomes really high, it can go through the wall and therefore no ‘collisionstart’ event is fired. After enabling CCD on the bullet, it starts colliding the wall properly, but I still don’t see any ‘collisionstart’ events fired :frowning:

The same happens when FPS drops below 15-20 and the distance traveled by the bullet per frame is big enough. Bodies collide but without firing any events.

1 Like

That indeed sounds like a bug or a Bullet system not implemented in Ammo.js/Playcanvas.

As a temporary solution, if performance allows it, I would try doing a raycast per frame and check the distance threshold to invoke manually a collision event.

1 Like

I would agree. For bullets, I’d use raycasts!

Out of curiosity, @Igor, are you using the ‘legacy’ physics, or does your project have the new WebAssembly based version of ammo.js?

Yeah, raycasting could be a solution, pretty rough though. Thanks guys!

To @will: we faced the bug in both legacy and WebAssembly builds.

1 Like

2 posts were split to a new topic: Not getting collision callbacks with physics