jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.71k stars 447 forks source link

How to move body during ContactAdded? #972

Closed LittleCodingFox closed 8 months ago

LittleCodingFox commented 8 months ago

I'm trying to make a teleporter and I want the character to be teleported when touching a teleport surface, but the app freezes instead. I thought it was due to locks, but even adding lock checking code to use the NoLock variants of BodyInterface, it will then assert that it has no rights (BodyAccess::sCheckRights(BodyAccess::sPositionAccess, BodyAccess::EAccess::ReadWrite))

I looked at the issues and discussions and I'm not having much luck figuring this out, and I'd really appreciate some help!

Thank you very much!

jrouwe commented 8 months ago

You can't move a body in the contact callback, you need to remember that the contact happened and do it after the physics simulation step finishes (and possibly reject the contact point so that the other body is not affected).