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

LinearCast Body missed in Sensor contact #1142

Open
Qendolin opened this issue Jun 13, 2024 · 4 comments
Open

LinearCast Body missed in Sensor contact #1142

Qendolin opened this issue Jun 13, 2024 · 4 comments

Comments

@Qendolin
Copy link

Hello, I've noticed an issue where rigid bodies using JPH::EMotionQuality::LinearCast do not report contacts with sensors when moving at high speed (~100 m/s).

Here is my character body creation code:

JPH::Ref<JPH::CharacterSettings> character_settings = new JPH::CharacterSettings();
character_settings->mMaxSlopeAngle = JPH::DegreesToRadians(45.0f);
character_settings->mLayer = ph::Layers::PLAYER;
character_settings->mShape = new JPH::SphereShape(0.25f);
character_settings->mFriction = 0.0f;
character_settings->mGravityFactor = 0.0f;
body_ = new JPH::Character(character_settings, JPH::RVec3(0.0, 0.0, 0.0), JPH::Quat::sIdentity(), 0, physics().system);
physics().interface().SetMotionQuality(body_->GetBodyID(), JPH::EMotionQuality::LinearCast);
body_->AddToPhysicsSystem(JPH::EActivation::Activate);

My sensor is a static body, roughly 0.2m thick. The character body is moved using body_->SetLinearVelocity before the physics update.

Using Jolt 4.0.2, and a 60Hz update interval with 1 collision step and the single threaded job system.

@jrouwe
Copy link
Owner

jrouwe commented Jun 13, 2024

Currently there is no support for rigid bodies with motion type LinearCast vs sensors (they will be treated as Discrete vs sensors):

// TODO: For now we ignore sensors
if (body2.IsSensor())
return;

@Qendolin
Copy link
Author

I see. Maybe that would we worth noting in the documentation?
Thank you for your quick response.

@AnuraDev
Copy link

so the right approach would be to use ContactListener::OnContactValidate and do rejects there?

sensors seems to be misleading in a way (from intuition point of view)
but the docs do mention what:

To create a sensor, either set BodyCreationSettings::mIsSensor to true when constructing a body or set it after construction through Body::SetIsSensor. A sensor can only use the discrete motion quality type at this moment.

overall looks like what for games you need a lightweight/fast event system in ContactListener so it does checks only for bodies with associated events/callbacks.

@jrouwe
Copy link
Owner

jrouwe commented Jun 16, 2024

so the right approach would be to use ContactListener::OnContactValidate and do rejects there?

You could use OnContactValidate to implement a sensor, but getting this call doesn't mean that this is the closest collision. Hits are roughly sorted based on closeness, so for an object with motion type LinearCast it may be that you later receive another call to OnContactValidate with a closer collision which will result in the actual contact point.

ContactListener::OnContactAdded indicates that there is an actual contact and you can specify that that contact should be treated as a sensor by setting ContactSettings::mIsSensor. This disables the contact, but since we only store the closest contact point during the LinearCast sweep, this also means that the body could penetrate the object behind the sensor.

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