Sweep question: Odd behavior and passing through colliders #346
-
Hi, I've got a bit of a question about how sweeping works, and subsequently a question about how to achieve a given effect. Firstly, are sweeps guaranteed to fire hits in any particular order? I'm currently working to expose a sweep where all you care about is the first hit to our users, but upon instrumentation of our sweep handler to debug what was going on, it appears that sweeps will sometimes query colliders that are further behind them first depending on where other colliders in the scene reside. I was following the example where you set In this picture you can see a sweep with this logic implemented querying a mesh-based collider past what would have been the first hit. This only happens when my character (which has a kinetic body and various other triggers/statics sprinkled in, I've verified these are within sane bounds and not infinitely huge or anything) is floating around the exact area as-pictured: The problem locations change depending on the angle of the sweep and what else is in the scene, so I'm suspecting it's some funny behavior with the internal optimization structures bepu uses to query things. Secondly, if sweeps can indeed happen in no particular order, how could I ensure that they're ordered by their Given what I'm observing, my hypothesis currently is that sweeps really don't guarantee any particular order and that's why you have to sort out the minimum Apologies for the lack of code snippets, I'm on my phone and also can't legally post it here, but I've gone through and triple-checked the code path leading back to bepu and it all seems to follow very closely with the examples I've seen to achieve the "only the first hit" functionality we're going for. I do believe this behavior is originating from bepu's side at this point. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yup, there is indeed no guarantee of order reported by the hit handler. As an implementation detail, the acceleration structure visits nodes based on which node bounding box is hit first by the ray/sweep, but there's no guarantee that hitting an object's bounding box first will imply that the object's actual geometry will be hit first (or at all). The hit handler is meant to be a minimal and direct report, so more complex queries like "a sorted list of impacts up until a maximum T value" would require postprocessing of the collected hits. That's not done by default because, while it is cheap, it's still a nonzero cost and not required by many common use cases. |
Beta Was this translation helpful? Give feedback.
Yup, there is indeed no guarantee of order reported by the hit handler. As an implementation detail, the acceleration structure visits nodes based on which node bounding box is hit first by the ray/sweep, but there's no guarantee that hitting an object's bounding box first will imply that the object's actual geometry will be hit first (or at all).
The hit handler is meant to be a minimal and direct report, so more complex queries like "a sorted list of impacts up until a maximum T value" would require postprocessing of the collected hits. That's not done by default because, while it is cheap, it's still a nonzero cost and not required by many common use cases.