Setting an 'on-screen' arrows angles!

Hello. Some days ago I’ve posted a question about how to spawn an arrow on your screen. I’ve got an answer to that -> Model Panel. The problem now, is that I can’t figure out how to set its angles so that it points to the right direction!
Right now, I’m using something like this : LocalPlayer:EyeAngles() - (LocalPlayer:EyePos() - TargetDir):Angle() , where TargetDir is the World Position of the target it should point at! There is a problem, though. It isn’t right. I am forgetting something important, and I can’t seem to find it … that’s why I need your help. ( The arrow isn’t pointing in the right direction )

Try just doing this:
lua:Angle()[/lua]

If I do that, the arrow will not change it’s angles if you move your head. ( change view angles )

[lua]local ang = LocalPlayer():EyeAngles()
local tang = (TargetDir-LocalPlayer():EyePos()):Angle()
ang:RotateAroundAxis(ang:Up(), tang.y-ang.y);
ang:RotateAroundAxis(ang:Right(), tang.p-ang.p);[/lua]

Try using this and setting the arrow’s angles to ang.

Still not pointing correctly … ( The arrow is pointing towards the object but with an offset. Edit #2: Still flawed )

Is it pointing the same direction no matter where you look?

Nope, after testing some more, it doesn’t point the direction no matter where you look.

Can you post the code you are using to create the DModelPanel and set the angles up so I can mess around with it?

Yes, in a couple of moment I’ll post it

[editline]07:56PM[/editline]

[lua]
local PANEL = {}

/---------------------------------------------------------
Init
---------------------------------------------------------
/
function PANEL:Init()
self:SetModel( “models/arrow.mdl” )

self.Visible = false
self:SetPos( ScrW() - 1 , 0 )  
  
 self:PerformLayout()  

end

/---------------------------------------------------------
LayoutEntity
---------------------------------------------------------
/
TargetDir = Vector ( 0,0,0 )
function PANEL:LayoutEntity ( Arrow )

 if ( !IsValid( MySelf ) ) then return end  

self:SetCamPos ( Vector( 0, 20, 0 ) )  
 self:SetLookAt ( Vector( 0, 0, 0 ) )  
 Arrow:SetModelScale ( Vector ( 0.5, 0.5, 0.5 ) )  
  
self:MoveTo( w * 0.3, h * 0.2 , 1, 0, 2 )  

for k,v in pairs ( player.GetAll() ) do
if v != MySelf then
TargetDir = v:GetPos()
end
end

 local ang = LocalPlayer():EyeAngles()  
 local tang = ( LocalPlayer():EyePos() - TargetDir ):Angle()  
 ang:RotateAroundAxis ( ang:Up(), tang.y - ang.y )  
 ang:RotateAroundAxis ( ang:Right(), tang.p - ang.p ) 

Arrow:SetAngles( ang ) 

end

/---------------------------------------------------------
PerformLayout
---------------------------------------------------------
/
function PANEL:PerformLayout()

self:SetSize( ScrW()*0.3, ScrW()*0.3 )

end

if ( Compass ) then Compass:Remove() end
Compass = vgui.CreateFromTable( vgui.RegisterTable( PANEL, “DModelPanel” ) )
[/lua]

Don’t judge this from formatting or how it’s coded. It’s written fast and just for testing. I will clean it if I solve it :slight_smile:

Play around with this.