How to determine if Angle is faced right or left of a Vector
3 replies, posted
Hello, Facepunchers! I have stumbled upon a problem making something. I need to detect wether if a position if right or left (Or perfectly aligned) with my character's rotation. For example if I have a point in the distance and I look right of it, I need a function that I look right of the target. If I look left of it, I need the function to return I look left of it. I have some ideas (Calculating the angle between the player and the object, then with calculations check how many degrees it is off the target), but I have no idea how to actually write them (Might as well be the time though, pretty late at me ;))
[lua]
function PLAYER:FacingVector( vec )
local relang = ( self:GetPos() - vec ):Angle()
local facing = relang - self:EyeAngles()
if( facing.y <= -1.5 ) then
return -1 -- Facing left
elseif( facing.y >= 1.5 ) then
return 1 -- Facing right
else
return 0 -- Facing directly
end
end
ply:FacingVector( ent:GetPos() )
[/lua]
Enjoy.
[QUOTE=Pyro-Fire;47682930][lua]
function PLAYER:FacingVector( vec )
local relang = ( self:GetPos() - vec ):Angle()
local facing = relang - self:EyeAngles()
if( facing.y <= -1.5 ) then
return -1 -- Facing left
elseif( facing.y >= 1.5 ) then
return 1 -- Facing right
else
return 0 -- Facing directly
end
end
ply:FacingVector( ent:GetPos() )
[/lua]
Enjoy.[/QUOTE]
Thanks! Going to test soon ;)
[url=https://github.com/LennyPenny/Lennys/blob/master/lua/Lenny/bHop.lua#L20-L29]Try modifying this.[/url]
Modify it with a.y instead of a.x
Sorry, you need to Log In to post a reply to this thread.