sbox-issues icon indicating copy to clipboard operation
sbox-issues copied to clipboard

Physics Contact Modification

Open rileyzzz opened this issue 1 month ago • 4 comments

What can't you do?

Unity (https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Physics.ContactModifyEvent.html) and Unreal (https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Chaos/FCollisionContactModifier) both offer a contact modification API, which allows you to set a custom solver which can selectively ignore/modify contact events.

Among other things, this allows you to perform advanced physics behaviors like cutting dynamic holes in objects, or creating "sticky" contact effects, or soft collisions where objects can "float" inside each other. (https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/AdvancedCollisionDetection.html)

How would you like it to work?

Ideally I would like something similar to Unity's implementation. https://docs.unity3d.com/6000.2/Documentation/ScriptReference/Physics.ContactModifyEvent.html

Essentially you set an event on the physics world which takes an array of modifiable contact pairs. You can iterate through these pairs, and then iterate the points in each pair, choosing to set the bounciness, friction, maximum impulse, normal, contact point, separation value, target velocity, or ignore the contact altogether.

This could go through the existing Physics OnIntersectionStart/Update/End API, or get its own API.

What have you tried?

We have basic contact events, but nothing in place to modify them.

Additional context

No response

rileyzzz avatar Nov 19 '25 05:11 rileyzzz

This would also work for me and #9446 Even Gmod had collision detection which you then could modify the result so they'd ignore each other

yuberee avatar Nov 19 '25 07:11 yuberee

This would also work for me and #9446 Even Gmod had collision detection which you then could modify the result so they'd ignore each other

Yep same for me, bcs right now I have some destructable props like lampposts or fences in my GTA like typed game but the collisions with cars can be really weird, sometimes the collision is crazy powerful and makes the lamppost fly into space and sometimes its the complete opposite, it's even worse with an heli or a plane, collision are even weirder. I had to deal with clamping the force etc.. but even with that there is always some weird inconsistency when colliding with the objects.

I would really like such a things to be implemented !

K3rhos avatar Nov 20 '25 04:11 K3rhos

My main use is also running over people, I'd like to ragdoll them the moment any impact is strong enough, but it will still process the collision from before they're physical so the crash still crashes.

yuberee avatar Nov 20 '25 09:11 yuberee

It's possible but I'll need to do it in a way where you can't modify any of the physics within the callback because that's not allowed

aylaylay avatar Nov 20 '25 09:11 aylaylay