- Home /
Raycaste vs trigger Colliders & Rigidbody performance
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
Answer by VadimMinsk · Aug 22, 2018 at 02:33 PM
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.
Your answer
Follow this Question
Related Questions
Performance hiccup on initial contact with rigid bodies 0 Answers
Physic processing takes a lot of time for one rigidbody 1 Answer
Limiting rigidbody physics influence on another rigidbody 0 Answers
Applying proper drag and center of mass for a vehicle 1 Answer
Random Performance Spikes due to Physics.Processing in a static scene. 1 Answer