# Find ents in a "tire" shape

For a SWEP I’m working on I need to find ents in a tire shape, meaning in a circle on one axis, and a box on another.

e.g.
Forward View

``````

__
|  |
|  |
|  |
|  |
|  |
|  |
|  |

``````

Then the side view would just be a circle.

Anyone know how I would go about doing this?
I thought about doing an ents.FindInBox combined with an ents.FindInSphere and using the ents that are in both, but that seems tricky and ineffecient.

Will the shape be axis aligned?

If the tire never moved angles, that’s how I’d do it

[editline]12:39PM[/editline]

:ninja:

It will be aligned to the Yaw of the players EyeAngles.

[editline]01:06PM[/editline]

Would you be able to define your box, then use vec:Rotate() based on eyeangles to get the corrrect bounding box?

[editline]01:37PM[/editline]

Just tried this in a SENT that i spectated (In ENT:Think())
[lua]
local boxBound1 = Vector(-15, 30, 30)
local boxBound2 = Vector(15, -30, -30)
local eyeAngs = self:GetOwner():EyeAngles()
boxBound1:Rotate(eyeAngs)
boxBound2:Rotate(eyeAngs)
boxBound1 = boxBound1 + self:GetPos()
boxBound2 = boxBound2 + self:GetPos()
debugoverlay.Box(Vector(0,0,0), boxBound1, boxBound2, .25, Color(200,100,100,127))
[/lua]

Didnt work too hot, the box didnt really rotate, the dimensions just got all fucked.

[lua]
local off = ent:GetPos()-tireCenter

local r = ply:EyeAngles():Right()
local d = r:Dot(off)

if d+d < tireWidth and off:Distance(r*d) < tireRadius then

``````--ent is inside tireshape
``````

end
[/lua]

Untested.

Is tireWidth the entire width? or does this account for an offset so the tires left side isnt at the center of the eyeview?

[editline]02:10PM[/editline]

And also how do you reference the ents inside the tire with your code?

tireWidth is the entire width.

Just iterate ents.GetAll() and apply that check to each of them.

You mean like… uh.
FindInCylinder or something?
The only way I could think of doing it is iterating through entities found in ents.FindInBox, then removing all entries that are more than N distance from the centre of the box (to fix any that are off the edge of the “wheel”)

Yeah Cylinder - I couldn’t think of the word when I made the thread, but I did get this working with ralle’s help.
The code:

for k, v in pairs(ents.GetAll()) do
local off = v:GetPos() - cylinderOrigin
local r = self.Owner:EyeAngles():Right()
local d = r:Dot(off)
if d+d < cylinderHeight and off:Distance(r*d) < cylinderRadius then
–Ents have been found
end
end