Entity:GetAttachment
Açıklama
Eklentinin ID'sine göre yönünü ve pozisyonunu alır, eklenti mevcut değilse hiçbir şey döndürmez.
Bu fonksiyonun güncelleme hızı, Scripted Entities için ENT.AutomaticFrameAdvance ayarı ile sınırlıdır!
Bu fonksiyon, GM:CalcView içerisinde kullanıldığında viewmodel'lar için hatalı değerler döndürür.
Sorun Takipçisi: 1255
Sorun Takipçisi: 1255
Argümanlar
Döndürülen Değerler
1 table (AngPos yapısı ile) veya nil
Eklentinin açısını ve pozisyonunu içeren tablo veya mevcut değilse
nil. AngPos yapısına bakınız. En önemlisi, tablo Ang ve Pos anahtarlarının yanı sıra Bone anahtarını da içerir.Örnek
Bir oyuncunun view model'ının namlu (muzzle) pozisyonunu alır.
local vm = ply:GetViewModel()
local obj = vm:LookupAttachment( "muzzle" )
if (obj > 0) then
local muzzle = vm:GetAttachment( obj )
print( muzzle.Pos, muzzle.Ang )
end
Örnek
Eğer modelin bir "muzzle" eklentisi varsa, oyuncunun view model'ının namlusuna yeşil bir küp çizer. Bu, eklentiyi view model projeksiyon uzayına doğru bir şekilde çevirir.
local function FormatViewModelAttachment(vOrigin, bFrom --[[= false]])
local view = render.GetViewSetup()
local vEyePos = view.origin
local aEyesRot = view.angles
local vOffset = vOrigin - vEyePos
local vForward = aEyesRot:Forward()
local nViewX = math.tan( view.fovviewmodel_unscaled * math.pi / 360)
if (nViewX == 0) then
vForward:Mul(vForward:Dot(vOffset))
vEyePos:Add(vForward)
return vEyePos
end
local nWorldX = math.tan( view.fov_unscaled * math.pi / 360)
if (nWorldX == 0) then
vForward:Mul(vForward:Dot(vOffset))
vEyePos:Add(vForward)
return vEyePos
end
local vRight = aEyesRot:Right()
local vUp = aEyesRot:Up()
if (bFrom) then
local nFactor = nWorldX / nViewX
vRight:Mul(vRight:Dot(vOffset) * nFactor)
vUp:Mul(vUp:Dot(vOffset) * nFactor)
else
local nFactor = nViewX / nWorldX
vRight:Mul(vRight:Dot(vOffset) * nFactor)
vUp:Mul(vUp:Dot(vOffset) * nFactor)
end
vForward:Mul(vForward:Dot(vOffset))
vEyePos:Add(vRight)
vEyePos:Add(vUp)
vEyePos:Add(vForward)
return vEyePos
end
SWEP.BoxAttachment = "muzzle"
SWEP.BoxMins = Vector(-2, -2, -2)
SWEP.BoxMaxs = Vector(2, 2, 2)
SWEP.BoxColor = Color(0, 255, 0)
function SWEP:ViewModelDrawn()
local pOwner = self:GetOwner()
if (not pOwner:IsValid()) then return end
local pViewModel = pOwner:GetViewModel()
if (not pViewModel:IsValid()) then return end
local uAttachment = pViewModel:LookupAttachment(self.BoxAttachment)
if (uAttachment < 1) then return end
local tAttachment = pViewModel:GetAttachment(uAttachment)
if (tAttachment == nil) then return end
render.DrawWireframeBox(FormatViewModelAttachment(tAttachment.Pos, false), tAttachment.Ang, self.BoxMins, self.BoxMaxs, self.BoxColor, true)
end
Tüm sunucular · GmodTR Launcher · Rehber · GMod Wiki · GmodTR nedir? · Sunucu ekle · Discord