Collision Contact Point(s) without Physics

I have two rigidbodies, both non-kinematic. I would like to detect when they collide, but I do not want them to impart motion on each other. I looked at OnTriggerEnter, but I need to know the collision point or, ideally, intersection of the two objects, as in OnCollisionEnter’s Collision.GetContacts.

My objects are arbitrarily shaped, so the built-in overlap functions such as [OverlapBox](https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html) don’t fully work in this case. My current idea for how to move forward is to build one of my bodies out of boxes and run OverlapBox on FixedUpdate for each box, but that seems incredibly messy.

Should be theoretically possible, since I’m asking for less behavior rather than more, but all of the solutions I can find leave out either the collision point or the lack of collision force.

Perhaps make clones of these objects, set to use another layer(s) that are set to NOT collide with anything in your scene.

Each FixedUpdate() drive your clones to the position / rotation of your main Rigidbodies, and observe when they collide, get all that touchy stuff off their collisions while the original Rigidbodies pass through each other because they are set to trigger.

1 Like

Ah, yup, that does it. Removed collision between their layers and added a “Hitbox” layer with cloned meshes attached to the parents, and OnCollisionEnter still works. Thanks!

1 Like

I’m curious what this is for… is it a hatchet-throwing game?

If you make them kinematic and enable static/kinematic pairs, you’ll still receive OnCollisionXX-events without the actual collision resolution. If you absolutely need them to be dynamic, then you can use Unity - Scripting API: Physics.ContactModifyEvent to modify the contacts prior to resolution, to ignore the collision but keep the manifold, for instance.

3 Likes

Need non-kinematic, sadly. I definitely like ContactModifyEvent for the lack of need for additional objects, layers, etc. I think in this particular case I’ll stick with the hitboxes and layers since I don’t want to turn off physics for the object entirely, just on specific collision pairs.

No, though that is a good idea to use this to ignore collision for a fraction of a second, then halt motion to “embed” the hatchet…


It’s more a Beat Saber type thing that I’m messing around with for fun. Boxes fly at you, bouncing off terrain and each other, and there are a few weapons to slice them, shoot them, etc. Haven’t done much with it yet, but I’m trying to keep the logic generic so I can add stuff later down the line.

1 Like