Confusing ents.FindInCone behaviour.

Hi all, I’m trying to use ents.FindInCone to project a view-cone for a homing missile. Instead of returning all entities within the cone, it seems to return all entities in a 180 degree arc forward of the cone position.

For example, this code:



    local missilePos = missile:GetPos()
    local missileForward = missile:GetForward()
    
    local found = ents.FindInCone(missilePos, missileForward, 3000, 30)
    
    for k, ent in pairs(found) do
    
        debugoverlay.Line( missilePos, ent:GetPos(), 15, Color(0, 0, 255), true )
    
    end


produces these lines:

https://dl.dropboxusercontent.com/u/902553/ShareX/2015/09/2015-09-18_00-05-11.jpg

I’ve tried with different angles. I’ve also tried converting to radians just in case it was that, same result every time.

I can post-process the list with dot product for now, but I’m not sure why this is happening!

My guess is the cone radius is too high.

I thought it could have been that because I had it set to 50000 at first, but it does the same thing with 3000. Any radius smaller than that is useless to me, it’d become a very short-range missile :v:

It appears that ents.FindInCone is bugged. No matter what the angle is, it returns as if the angle was 180, I just tested that.

EDIT:

Here’s a makeshift solution for you.

[lua]
local function find_in_cone(cone_origin, cone_direction, cone_radius, cone_angle)
local entities = ents.FindInSphere(cone_origin, cone_radius)
local result = {}

cone_direction:Normalize()

local cos = math.cos(cone_angle)

for _, entity in pairs(entities) do
	local pos = entity:GetPos()
	local dir = pos - cone_origin
	dir:Normalize()
	local dot = cone_direction:Dot(dir)

	if (dot > cos) then
		table.insert(result, entity)
	end
end

return result

end

local entities = find_in_cone(Entity(1):GetShootPos(), Entity(1):EyeAngles():Forward(), 100, math.pi/6)

local color = ColorRand()
for k, v in pairs(entities) do
v:SetColor(color)
end
[/lua]

That’s great, thank you. If this is a bug then I’ll go and weigh in on github. Seems like the sort of thing that should already have been noticed though.