So I'm trying to detect things within x radius and without y radius. A donut shaped area of detection. My plan is to use two OverlapSpheres and remove colliders from the small one from the collection the large one returns.
Is this the best way to do this? If it is, what's the best way to filter an array like that? There don't seem to be any helper functions like Array.Without.
Well that's quite simple:
// C# and needs using System.Collections.Generic;
public static List<Collider> GetDonut(Vector3 pos, float InnerRadius, float OuterRadius)
List<Collider> outer = new List<Collider>(Physics.OverlapSphere(pos,OuterRadius));
Collider inner = Physics.OverlapSphere(pos,InnerRadius);
foreach (Collider C in inner)
Here the JS version:
function GetDonut(pos : Vector3,InnerRadius : float, OuterRadius : float) : List.<Collider>
var outer : List.<Collider> = new List.<Collider>(Physics.OverlapSphere(pos,OuterRadius));
var inner : Collider = Physics.OverlapSphere(pos,InnerRadius);
for (var C : Collider in inner)
Well, the Name is not really good but it's just a sample ;)
This function returns a List<> but with .ToArray() you can convert it back to an array if you really want.