Entity/SetEyeTarget

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Added an example)
 
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=SetEyeTarget
 
|Parent=Entity
 
 
|Description=Sets the position an entity's eyes look toward.
 
|Description=Sets the position an entity's eyes look toward.
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=Yes
 
|IsClass=Yes
 +
|Name=SetEyeTarget
 +
|Parent=Entity
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 12: Line 12:
 
}}
 
}}
 
{{Example
 
{{Example
|Description=Makes an NPC (self) look into a nearby player's eyes.
+
|Description=Makes an NPC (self) look into a nearby player's eyes.
|Code=for p, ply in pairs(player.GetAll()) do
+
|Code=for p, ply in pairs(player.GetAll()) do
 
     if(ply:EyePos():Distance(self:EyePos()) <= 60) then
 
     if(ply:EyePos():Distance(self:EyePos()) <= 60) then
 
         self:SetEyeTarget(ply:EyePos())
 
         self:SetEyeTarget(ply:EyePos())
Line 19: Line 19:
 
     end
 
     end
 
end
 
end
 +
}}
 +
{{Example
 +
|Description=Makes an entity look at a vector the way the eyeposer does it
 +
|Code=local lookat = Vector( 0, 0, 0 )
 +
 +
local attachment = ent:GetAttachment( ent:LookupAttachment( "eyes" ) )
 +
local LocalPos, LocalAng = WorldToLocal( lookat, Angle( 0, 0, 0 ), attachment.Pos, attachment.Ang )
 +
ent:SetEyeTarget( LocalPos )
 
}}
 
}}

Latest revision as of 12:25, 10 September 2016

 Entity:SetEyeTarget( )

Contents

Description

Sets the position an entity's eyes look toward.

Arguments

Vector pos

The world position the entity is looking toward.

Examples

Example

Makes an NPC (self) look into a nearby player's eyes.

for p, ply in pairs(player.GetAll()) do
    if(ply:EyePos():Distance(self:EyePos()) <= 60) then
        self:SetEyeTarget(ply:EyePos())
        break
    end
end


Examples

Example

Makes an entity look at a vector the way the eyeposer does it

local lookat = Vector( 0, 0, 0 )

local attachment = ent:GetAttachment( ent:LookupAttachment( "eyes" ) )
local LocalPos, LocalAng = WorldToLocal( lookat, Angle( 0, 0, 0 ), attachment.Pos, attachment.Ang )
ent:SetEyeTarget( LocalPos )


Personal tools
Navigation