Get Vector3s in range

Hello guys,

I want to make it simple for your and my sake

I just want to know the technique of getting the Vector3s in range from
an array of Vector3s

I’d prefer Javascript but C# will work too

Just tell me how it works and should knows or even links to tutorials or the manual


[Unity 5.4 (Older will do)]

[I Have Hundreds(Maybe Thousands) of Vector3s]

[My Game has IMGUI And custom editors]

[If you want the script I can give it to you, just comment]


If your candidate vectors are in a simple array, there’s really only one approach:

  • loop through the array
  • calculate the vector difference between each item in the array and your “target” vector3 (V = Vectorₓ - Vector₀ )
  • calculate the squared magnitude of the difference (V.sqrMagnitude)
  • if this exceeds the square of your “range”, discard the candidate, otherwise keep it
  • move on to the next item in the array