- Home /
Find nearest contact point inside trigger
I have a sphere collider trigger and i need to find the closest contact point on various other colliders.
I've tried using "ClosestPointOnBounds" but have read here that the reason this isn't working is because i am dealing with rotated objects, and this method is "Axis Aligned", so this is a no go, unless someone knows a way to translate the axis aligned results into something meaningful?
I also can't simply raycast towards the origin of the "other" collider, as I'm dealing with large and variously shaped colliders, and I do need the closest point, so this will often give an unacceptable result for my purposes.
And I can't use the method suggested here of finding the nearest vertex as im not only dealing with mesh colliders, but spheres, boxes, etc.
I don't think i can simply use a kinematic rigidbody and normal collision detection, because I have to avoid my trigger sphere having any effect on the objects im colliding with.
Desperate at this point, so if anyone has a solution you will forever have my adoration.
Answer by notgnilgum · Aug 12, 2019 at 07:12 PM
Solved for those stumbling across this in the future:
Use "ClosestPoint" not "ClosestPointOnBounds" and make sure "convex" is ticked on all your mesh colliders!
Answer by imaginationrabbit · Aug 11, 2019 at 10:51 PM
Have you tried using ClosestPoint? link text You can use it to get the closest point from your trigger collider to the other collider then use the point it gives you with the trigger collider and ClosestPoint and that will give you the point of contact between the two.
You could also use the collider size/radius to fire a Ray in the direction of the other collider and use Ray.GetPoint link text
For the distance to use on GetPoint- you can use the position GetClosestPoint gives you- just some ideas-
I tried closest point but it was giving me an error message about not working with most collider types, and I assume it has the same axis aligned problem as closest point on bounds? Though if I'm just being dumb I'd love to be corrected. And again, I can't just ray cast towards the other collider as the origin will often be nowhere near the closest point in my case.
After some fiddling, there is a tick box "convex" on the mesh collider which magically makes "ClosestPoint" work perfectly, so you are actually on the money, thanks!