ents.FindInCone

From GMod Wiki

Jump to: navigation, search
Function
Syntax ents.FindInCone( Vector Pos, Vector Dir, Float Distance, Float Radius )
Where is this used?
Description:
Find all entities within a specified hemisphere or spherical cap - probably useful for Line Of Sight.
Returns: Table : Entity
Part of Library: Ents
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Ents.FindInCone]Ents.FindInCone [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Description

The shape in which this function finds something is probably a spherical cap.

That means it's part of a sphere that has its center at vPos and is of radius fRadius.

That sphere is then cut at a plane perpendicular to vDir, in fDistance units from vPos.

Mathematically:

local DistV=E:GetPos()-vPos
if
  DistV:Dot(vDir) > fDistance -- the plane
and 
  DistV:Length() < fRadius -- the sphere
then add_to_list(E) end

Possible >= and/or <= instead of > and <

Example

DescriptionKills any NPCs in the SWEP's viewcone.
Used onNewerServer.png
Code
local ConeEnts = ents.FindInCone(self:GetOwner():GetShootPos(),
     self:GetOwner():GetAimVector(),
     65535,90);
 
for i, pEnt in ipairs(ConeEnts) do
     if pEnt:IsNPC() then
          pEnt:TakeDamage(5000,self:GetOwner(),self);
     end
end
OutputAny NPC within 90 degrees of the weapon's owner's aim is killed.


See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox