Hey everyone so I had a general performance question.
Currently, I’m making a spin wheel like the wheel of fortune and have come up with two possible ways to solve my problem.
1. Using Rigidbodies and triggers to see which spin the wheel option I landed on. And just having a permanent trigger box that tells me which slot on the spin wheel is currently on it via ontriggerstay/ ontrigger enter… etc.
2. Using a linecaste/raycasting to read which wheel option I’ve landed on.
Basically, they both do the same thing effectively but for minor performance differences I was curious which would be more optimal
The ultimate performance is to do no calculations at all. For such simple case, as a spinning wheel you can know your sector using local rotation angle.
int Sector = MathF.FloorToInt(rotation.x / NumberOfSectors)
As for the general quastions linecasting, raycasting and especially spherecasting generally performe significantly worse than OnTriggerEnter/OnTriggerStay, because Contact detection uses nice algorithms, that discard noncolliding bodies early, and don’t even start unnecessary calculations.
With linecasts inside your update you evaluate the situation every frame, against all the objects you have.
None of this is written in stone actually. For example, If you manage masks good enough, so you check only against few items, and have thousands of triggers on the scene, you can have linecasts work faster than OnEnter/OnExit. Always check, what’s profiler saying.