Trying to get a arrow model that is drawn on the HUD to point at the location of a ent within the world. I can’t seem to get it to point in the right direction, I’m doing a pretty awful job at trying to figure out this issue honestly.
My code:
function GM:SetupArrowGuide()
if IsValid(self.ShopDirPointer) then
self.ShopDirPointer:Remove()
end
self.ShopDirPointer = vgui.Create("DModelPanel")
self.ShopDirPointer:SetSize(256, 256)
self.ShopDirPointer:SetPos(ScrW() * 0.01, 0)
self.ShopDirPointer:SetModel("models/trader/arrow.mdl")
local mn, mx = self.ShopDirPointer.Entity:GetRenderBounds()
local size = 0
size = math.max(size, math.abs(mn.x) + math.abs(mx.x))
size = math.max(size, math.abs(mn.y) + math.abs(mx.y))
size = math.max(size, math.abs(mn.z) + math.abs(mx.z))
self.ShopDirPointer:SetFOV(40)
self.ShopDirPointer:SetCamPos(Vector(size, size, size))
self.ShopDirPointer:SetLookAt((mn + mx) * 0.5)
function self.ShopDirPointer:LayoutEntity(ent)
local ShopDirPointerRotation
local ShopLoc = GAMEMODE.CurrentTraderPos
if not ShopLoc then return end
local PlayerPos = LocalPlayer():GetPos()
if ShopLoc.Z > PlayerPos.Z + 50 or ShopLoc.Z < PlayerPos.Z - 50 then
ShopDirPointerRotation = LocalPlayer():WorldToLocal(PlayerPos - ShopLoc):Angle()
else
local FixedZPos = ShopLoc
FixedZPos.Z = PlayerPos.Z
ShopDirPointerRotation = LocalPlayer():WorldToLocal(PlayerPos - FixedZPos):Angle()
end
ShopDirPointerRotation.p = 0
ent:SetAngles(ShopDirPointerRotation)
end
end