Quantumenace wrote:What is it about colliders.Poly that takes up so much CPU time? Do all the nested functions and vector methods contribute lots of overhead compared to the actal math? I had to make my own polygon-circle collision function to minimize chances of lag.
I highly doubt yours is more efficient. Either that or it's not actually working like you think it is.
The problem is that there really isn't a good solution to the problem of arbitrary polygon collision detection. There ARE reasonable solutions to the slightly more constrained problem of convex
The reason colliders.Poly takes up a lot of CPU time is that it, at construction time, triangulates the polygon. This allows any arbitrary polygon (as long as its edges don't cross over) to be split into a set of convex polygons which can be used for collision detection.
The downside to this is that calling "colliders.Poly" every frame is very slow (but note that's the construction function, not the collision functions).
That's why you're not encouraged to do that.
Instead, you're encouraged to use colliders.Poly once
, store the result, and then transform it by moving, rotating, scaling, etc.
The only reason you'd need to call colliders.Poly again would be if the shape were changing in real-time in a non-simple way - at which point you'd be better off either using your own function, or managing a set of triangle colliders yourself.
In short, it's very likely you're just using it wrong.