Gmod |实体繁殖


if SERVER then
function SWEP:PrimaryAttack()
if self.Owner:GetEyeTrace().HitPos:Distance(self.Owner:GetPos()) < 100 then
local entity = ents.Create( "gred_emp_grw34" )
if ( !IsValid( entity ) ) then return end 
entity:SetPos( self.Owner:GetEyeTrace().HitPos )
local entang = self.Owner:GetAngles()
entity:SetAngles(Angle(0, entang.y, 0) +Angle(0, 180, 0))
entity:SetModel("models/props_artillery/german/r_mortar_gw34.mdl" )
entity:Spawn()
self.Owner:StripWeapon( "turret_entplace" )
end
end

function SWEP:SecondaryAttack() end
end

这是我用武器生成实体的代码,现在问题是实体在地板上生成,所以我试图添加一些高度,有人能帮我吗?

实体的位置是self.Owner:GetEyeTrace().HitPos,因为您可能在看地板,所以实体在地板中生成。我想你有这样的东西。

你需要做的是抵消头寸。可以这样做:

local z_offset = 5 -- the offset you need (depends on the entity)
hitPos = self.Owner:GetEyeTrace().HitPos -- the position of the eye's hitting point
spawnPos = hitPos:Add(Vector(0, 0, z_offset) -- offset the pos
entity:SetPos( spawnPos )

关于偏移量,我(在gmodwiki上(找不到任何东西来确定它…我认为你需要尝试不同的偏移量。。。此外,若您有其他实体要派生,您可能还需要制作一个具有不同偏移量的表。

最新更新