Tunneling problem with CCD enabled bodies
Hello ! I'm encoutering a problem with my objects/bodies. I'm working on JS 3D video-game which takes place in space (so no gravity) but it isn't a space simulation. More like an arcade video game.
So, the player controls a space ship (third person view) and can fire lasers (they are small boxes geometry which are going pretty fast), I enabled CCD on both bodies (spaceship and each laser body/collider). But when a player fires lasers on another player's spaceship at a certain angle, we can experiment tunneling.
https://github.com/user-attachments/assets/76d83d8e-9cf7-4754-b0e8-c304b7afc733
I thought at first time it was because the lasers are moving really fast (like X-wings lasers in star wars movies) or because the spaceship collider geometry isn't clean, so maybe some faces of the model are glitching (it was a TriMesh).
So I tried several things:
- added a RayCast on my laser firing so a ray testing is performed each step, on each laser, to know if a collider collide or will collide the laser pretty soon ( => the system worked but I experienced tunneling too)
- modified my spaceship collider (custom) geometry to something more simple, less complex, even tested a relatively thick cuboid geometry
- Lowered the lasers' speed to determine if the tunneling is related to it ( => it is, because I experience a lot less tunneling with low speed, but it's not the feeling I want).
- modified my lasers collider geometry to make it a little bigger
- set my bodies to
setCanSleep(false)because it can happen when a spaceship isn't moving, so I thought maybe it was because of Sleeping mode - tried to edit
IntegrationParameters.maxCcdSubstepsto increase it but didn't work I think ? Or at least I didn't notice changes in my problem
But nothing significant or relevant to fix the tunneling problem with all this.
Few things to note :
- My laser colliders are set to sensor and the bodies to
KinematicVelocityBasedwith CCD enabled; - My spaceship body is set to dynamic (and I control its translation with its velocity, it's not very clean but it do the job)
- It's a multiplayer game so my physic engine is server-side and graphics engine is only client-side.
I don't really know what to do now. I will try to update this issue with a simplified version of my project I can share with you, if you're interested to help me. But if you already have some clues, especially with the IntegrationParameters.maxCcdSubsteps parameter which doesn't seem to change collision accuracy, feel free to share your thoughts :)
Have you tried using the built-in Rapier debugger yet?
I created a Three.js helper class that adds your world buffer to the scene as a 3D object:
https://github.com/doppl3r/resume/blob/master/src/js/Debugger.js
Simply run the update() method whenever you run world.step(). This should help visualize why your bodies appear to be tunneling with CCD enabled.
Thank you for your answer.
That's a really good point but actually, in my project, Rapier is server-side and my graphics engine (Three.js) is client-side. Rapier updates position and send them to clients. With my infrastructure, I don't think it'll be possible to send complete geometries to clients, or I'll need to implement the debugger server-side and client-side which seems a bit redundant...
And because I tested cuboid geometries instead of custom geometries for my bodies/colliders, a part of me think it might not help me as it should.
But I will try it anyway, as I tend to reproduce this bug in a smaller environment than my video-game prototype (like with no server at all, only client-side, with simpler shapes, etc....)
(sorry I closed the issue by missclick 😅, it's my first issue published in Github so I'll need a bit of time to see how it works)
It seems rapier is easier to tunneling, compare to others physics engine. https://lo-th.github.io/phy/index.html?E=w_rapier#simple
switch engine:
set objects num:
It seems rapier is easier to tunneling, compare to others physics engine. https://lo-th.github.io/phy/index.html?E=w_rapier#simple
switch engine:
set objects num:
Oh it's interesting ! Very nice tool to compare Js physics engines. thanks !
So yeah, Rapier seems easier to tunneling if substep is equal to 1, but if we set it to like 5 it seems more relevant.
Do you know if, in your example, the substep parameter can refer to integrationParameters.maxCcdSubsteps in Rapier.JS ? Or is it a tweak to increase global engine steps ?
Because in my project, I can't figure out how to modify integrationParameters.maxCcdSubsteps properly 😅

