Distance Calculation vs OnTriggerStay


I’d like to know, which would use less CPU clock.

Briefly instantiate a Trigger sphere collision with a function OnTriggerStay.


Calculate the distance between two objects and initialize the proper functions accordingly?

Thank You

Basic math calculations are always going to be cheaper than using the OnTrigger or OnCollision method groups because of built in overhead when utilizing them. Assuming you cache your variables correctly in your own distance code, it should be faster, but I don’t know if it will be an appreciable difference if profiled unless you’re making heavy use of OnTrigger.

A spherical trigger uses the Distance-calculation and some additional comparisons(object name, is it a trigger, and things like that).

A sphere has a radius and that is the distance from the center to the edge.

I made an example for you:
So calculating the distance costs less cpu power, because there are less things to check.

alt text