Author Topic: Best Way To Search For Players In A Box [Solved]  (Read 1079 times)

Any ideas? I know that I a containerBoxSearch isn't accurate for players and vehicles, and I can't use a trigger.
« Last Edit: October 16, 2015, 03:35:54 PM by jes00 »

Loop through all player objects, save their current location and check if it is in range of the set of coordinates.

check if it is in range of the set of coordinates.
It's specifically this part he needs to know how to do.
It's not as easy when the area in question is a box, as opposed to a sphere.

Select the corner closest to 0;0 and subtract each 3f so they are relative to 0;0. Jes has a lot of experience coding so he should be able to manage the many things that he needs to keep track of.
« Last Edit: October 16, 2015, 01:06:53 PM by Dannu »

do a container search to get the players close to the area you are checking
compare the players position to the x1, x2, y1.. (etc.) of the box to check if they are inside the box or not

ie

while(container find next player)
{
      if(
            pl.x+pl.radius > box.x-(box.width/2) && pl.x-pl.radius < box.x+(box.width/2) &&
            pl.y+pl.radius > box.y-(box.length/2) && pl.y-pl.radius < box.y+(box.length/2) &&
            pl.z+pl.height > box.z-(box.height/2) && pl.z-pl.height < box.z+(box.height/2)
      )
      {
             //do player stuff
      }
}


assuming the x y z coordinates are located at the center of each of these objects
« Last Edit: October 16, 2015, 02:28:42 PM by Swollow »

Oh. Well. Didn't think of that for some reason. And there I was trying to make a hacky box search method with a trigger(which wouldn't have worked anyways because if you create a trigger around something then it doesn't count as something "entering" it until it moves).

It's not as easy when the area in question is a box, as opposed to a sphere.
I actually find it's easier to do the comparisons of X/Y/Z axis vs finding the distance from the center of the sphere

I actually find it's easier to do the comparisons of X/Y/Z axis vs finding the distance from the center of the sphere

I disagree

            pl.x+pl.radius > box.x-(box.width/2) && pl.x-pl.radius < box.x+(box.width/2) &&
            pl.y+pl.radius > box.y-(box.length/2) && pl.y-pl.radius < box.y+(box.length/2) &&
            pl.z+pl.height > box.z-(box.height/2) && pl.z-pl.height < box.z+(box.height/2)

vs

Code: [Select]
            VectorDist(pl, box) < box.radius + pl.radius


Might be faster for the CPU though thanks to the square root operation in VectorDist.

using vectordist will take longer when pitted against raw opperators