In Unity, I have Trigger Colliders, and catch the OnTriggerStay(Collider other) events.

Once two Colliders are touching, how do I get the Force vector to make them want to separate again?

In the example below, I have a Sphere and a Box Collider touching. The OnTriggerStay is being called for the Sphere.

enter image description here

I cannot use the center positions of the transforms to get a direction, as that would not give me a very good force vector:

enter image description here

And I do not think I can use the Collider.ClosestPointOnBounds to figure out the Box touch position, because the point I look from (center of Sphere), could be inside the Box Collider itself, which I understand will just return me back the center of the Sphere again. I would not be able to resolve any force vector from that.

enter image description here

  • \$\begingroup\$ Are your colliders always in box-sphere pairs, or do you need to handle other pairs? \$\endgroup\$ – DMGregory Jan 4 '19 at 19:50
  • \$\begingroup\$ Well, box-sphere pairs would be a good start if there is no general way of solving this. =) \$\endgroup\$ – Kim Jan 6 '19 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.