[SOLVED] Ammo.js not returning collision callbacks

Hello everybody. I did my reading and I am aware that this is an old issue with Ammo.js not giving the collision details to play canvas.

Did anybody find a solution for this? My game is something a little bit like pong, I spawn more than one ball and collision not firing happen a lot. I tried to work my way around the issue, ignoring it and creating a detection system not as accurate as collision but it is way more messy in game play now because of all the ‘ghost balls’ that do not fire collision events.

How did you solve this Ammo.js issue in your games?

Is the event not firing? Or is the ball going through the paddle? Are you moving the paddles via forces/velocity/something else?

It is not just the paddles. Some static objects with rigid bodies too (yes, I am setting then with teleport). I did some small testing area and even in that area at a random change there is no collision callback received.

Also, I am moving the ball by directly setting the liniarvelocity…I do this because the ball acts weird on bounce otherwise…(Friction and Restitution set on 0 on everything)

My guess is that using teleport might be an issue as you can teleport an object into another and perhaps it doesn’t trigger the collision event when that happens.

I am using teleport just once when the object is spawned to place it where I want. For the movement of balls I am directly setting liniar velocity like this:

this.entity.rigidbody.linearVelocity = this.direction.clone().scale(this.velocity);

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.


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:

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:


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