-
Notifications
You must be signed in to change notification settings - Fork 54
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
feat(colliders): added the ability to use sensors on colliders #90
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
||
/* Collider events */ | ||
collider1Events?.onCollisionEnter?.({ | ||
target: rigidBody2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there's a subtle difference here. rigidBody2
could be undefined. Same goes for the other events.
const rigidBodyHandle2 = collider2.parent()?.handle; | ||
|
||
if (!collider1 || !collider2 || rigidBodyHandle1 === undefined || rigidBodyHandle2 === undefined) { | ||
if (!collider1 || !collider2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that I couldn't trigger collision events on colliders which didn't have rigid bodies. The only reason I could see for this was that the event below requires a rigid body in the payload.
If we remove that I think we can enable collision events on standalone colliders.
} else { | ||
world.contactPair(collider1, collider2, (manifold, flipped) => { | ||
/* RigidBody events */ | ||
rigidBody1Events?.onCollisionEnter?.({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've re-used the existing events onCollisionEnter
and onCollisionExit
. The exit event is identical and even triggered in the same way below, but the enter event is quite different.
There's currently no way to differentiate on the exit event apart from checking whether sensor
is set to true. We could try that if we wanted to differentiate between contact collision and intersection collision.
4639363
to
5855483
Compare
Hey! Essentially:
Lots of parts have undergone a complete rebuild behind the scenes, and adding props like this will be streamlined when that's finished. Your points regarding the collision events for standalone colliders are valid, and I'll come back to them once I'm done refactoring, thanks for that! I'll keep this here for now as a reminder, and will lift some parts of it with you in the credits :) |
Sensors are added with a slightly different api in #100! |
I've added the ability to use sensor colliders: https://rapier.rs/docs/user_guides/javascript/colliders#collider-type
You can see it in action in the Collider Sensor demo.
Use Case
When a player throws a ball into a bucket, I need to figure out whether they've got it in the bucket or missed the shot.
Usage
RigidBody
Collider
PR Side effects
The collisition event signatures have changes -
target
(rigid body) may now be undefined in the case of colliders (these currently don't work standalone).manifold
andflipped
aren't passed through as part of the intersection version of the events.