dimforge / rapier.js

Official JavaScript bindings for the Rapier physics engine.
https://rapier.rs
Apache License 2.0
410 stars 56 forks source link

Tunneling problem with CCD enabled bodies #286

Open double-hash opened 1 month ago

double-hash commented 1 month ago

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:

But nothing significant or relevant to fix the tunneling problem with all this.

Few things to note :

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 :)

doppl3r commented 1 month ago

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.

double-hash commented 1 month ago

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)