Reputation: 11
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
This is my Code for spawning an entitiy with a Weapon now the problem is the Entity spawns in the floor so i am trying to add some Height to it can anyone help me with that?
Upvotes: 1
Views: 1937
Reputation: 38
The entity's position is self.Owner:GetEyeTrace().HitPos
and because you are likely looking at the floor the entity spawn in the floor. I think you have something like this.
What you need to do is offsetting the position. It can be done like this :
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 )
Concerning the offset, i can't find anything (on the gmod wiki) to determine it... I think you will need to try different offset... Also, if you have other entities to spawn, you may also need to make a table with the different offsets.
Upvotes: 1