Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tunneling problem with CCD enabled bodies #286

Open
double-hash opened this issue Jul 16, 2024 · 3 comments
Open

Tunneling problem with CCD enabled bodies #286

double-hash opened this issue Jul 16, 2024 · 3 comments

Comments

@double-hash
Copy link

double-hash commented Jul 16, 2024

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.

video_illustrating_tunneling.mp4

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.maxCcdSubsteps to 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 KinematicVelocityBased with 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 :)

@doppl3r
Copy link

doppl3r commented Jul 16, 2024

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 double-hash closed this as not planned Won't fix, can't repro, duplicate, stale Jul 16, 2024
@double-hash
Copy link
Author

double-hash commented Jul 16, 2024

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)

@double-hash double-hash reopened this Jul 16, 2024
@fy0
Copy link

fy0 commented Sep 14, 2024

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

set objects num:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants