- Home /
Which is more efficent? SphereCast, SphereCastAll, or OverlapSphere?
I am attempting to track and 'catch' balls in a multiball situation, so I need to know how to locate these balls and have my glove go after them. Each ball is tagged with a "Ball" tag, and the 'glove' uses it's transform and rigidbody in order to predict where the ball is going to land. Which method would be the best to target individual balls within range, select a random one and go after it?
Answer by HarshadK · Nov 18, 2014 at 01:42 PM
An OverlapShpere will give you all the balls within certain radius of your glove whereas a SphereCastAll will perform a sweep in the specified direction with a specified radius for the sphere (SphereCast will just report the first collider). So in your case OverlapShpere is what you need.
Also you can select a random ball from the list of returned colliders array by OverlapShpere. Or you can calculate distance of each ball from glove and then select a ball based on distance. This is really up to you as how you want to do it and how you want your gameplay to be.
You got there before me ;) @Harshad$$anonymous$$ is correct - the choice is not a matter of efficiency, it's a matter of choosing the right functionality for your application.
I had a thought that perhaps I could use a wide sphere collider and OnTriggerEnter to detect each ball, but I have no idea if this is more or less efficient.
@tanoshimi Just a tad bit of luck.
@Teonnyn If you are going to perform an OverlapSphere in each Update then you should consider using wide sphere collider and OnTriggerEnter since it will be efficient than OverlapShpere in each Update. It is a matter of consideration based upon how your need it to be. If you could elaborate on your precise needs then we might be able to provide something solid.
Your answer
![](https://koobas.hobune.stream/wayback/20220613171830im_/https://answers.unity.com/themes/thub/images/avi.jpg)