• Setting the position of an entities parent.
    6 replies, posted
I'm a bit new to lua and I'm working on something that holds gun, basically when the gun touches the entity it sets it parent to the gun holder, its pretty simple. What I need to know how to do is set the position of the gun when it hits the holder, I've tried setting it's position to the holders position plus the vector but it does not seem to work, it just goes somewhere in the map. I was wondering what I am doing wrong, any help would be much appreciated :).
ent:SetPos( holder:LocalToWorld( Vector( 0, 0, 0 ) )
[QUOTE=Busan1;47839712]ent:SetPos( holder:LocalToWorld( Vector( 0, 0, 0 ) )[/QUOTE] Still the same thing, it just goes somewhere random in the world. Not random just somewhere I can not find it.
[QUOTE=little_piggy;47839731]Still the same thing, it just goes somewhere random in the world. Not random just somewhere I can not find it.[/QUOTE] well try Entity( 1 ):SetPos( ent:GetPos() ) after and see where it goes, possibly you use bad values in vector?
[QUOTE=Busan1;47839776]well try Entity( 1 ):SetPos( ent:GetPos() ) after and see where it goes, possibly you use bad values in vector?[/QUOTE] Same thing, My original code:[CODE]function ENT:Touch( hitEnt ) local x = self:GetPos() if hitEnt:GetClass()== "spawned_weapon" then hitEnt:SetParent(self) hitEnt:SetParentPhysNum(1) hitEnt:SetPos(x + Vector(0, 0, 50)) end end[/CODE]
[QUOTE=little_piggy;47839802]Same thing, My original code:[CODE]function ENT:Touch( hitEnt ) local x = self:GetPos() if hitEnt:GetClass()== "spawned_weapon" then hitEnt:SetParent(self) hitEnt:SetParentPhysNum(1) hitEnt:SetPos(x + Vector(0, 0, 50)) end end[/CODE][/QUOTE] [CODE]function ENT:Touch( hitEnt ) local x = self:GetPos() if hitEnt:GetClass()== "spawned_weapon" then hitEnt:SetParent(self) hitEnt:SetParentPhysNum(1) hitEnt:SetPos(x + Vector(0, 0, 50)) Entity( 1 ):SetPos( hitEnt:GetPos() ); print( tostring( hitEnt:GetPos() ); print( tostring( self:GetPos() ); end end [/CODE] not sure how the SetParentPhysNum works but maybe try with LookupBone, FollowBone?
[QUOTE=Busan1;47839825][CODE]function ENT:Touch( hitEnt ) local x = self:GetPos() if hitEnt:GetClass()== "spawned_weapon" then hitEnt:SetParent(self) hitEnt:SetParentPhysNum(1) hitEnt:SetPos(x + Vector(0, 0, 50)) Entity( 1 ):SetPos( hitEnt:GetPos() ); print( tostring( hitEnt:GetPos() ); print( tostring( self:GetPos() ); end end [/CODE] not sure how the SetParentPhysNum works but maybe try with LookupBone, FollowBone?[/QUOTE] Thank you for this, this helps me a bit better with the vector much appreciated!
Sorry, you need to Log In to post a reply to this thread.