so I need to, in every frame, make a list of a particular type of object organized by distance but only if they are close enough (and if the amount of objects in this list ends up being shorter than, let's say x, it replaces the rest of the values with null). how do i go about doing this? here's kind of an image demonstration to show what I mean
#List of nearest specific object types in order of distance
9 messages · Page 1 of 1 (latest)
Using unity’s physics system will be the easiest, since it’ll do all the spatial partitioning stuff for you. So if each object has a sphere collider, you can there spherecast from the origin. Also you’ll wanna change the physics matrix so that the layers can’t hit themselves etc
As for that list thing, seems pretty weird but you could make your own datatype that does it, so if you try referencing an index that’s outside the bounds of the list of objects, but inside x, it returns null? Again - a really weird thing to do
Just don’t loop through your list adding null to every index between length and x - every frame that’s just wasting fps
how would this work in 2d though?
specifically this
Yep gonna 2nd relying on the physics engine for this
if you already have the reference of all the objects then you can try calculating the magnitude/sqrmagnitude and check if its greater than the given distance or not and you can do the physics2d.overlap circle but dont calculate it every frame send a callback whenever other objects are moved and then do it, in this case it will save you some performance