• [LUA Question/Issue] How I do to make an entity spawn according to the entity's spawner angles?
    3 replies, posted
Well, hello there. I know it might sound strange, but Im trying to make a soda machine for a... roleplaying gamemode. The thing is, I know how to make a entity to spawn another entity when you press E, I adjusted the spawn position of the soda to appear infront of the machine, but the thing is, that when I rotate the machine, the soda appears out of place. How I can set some kind of spawn pos according to another entity's angles?
You want to use [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7f2a.html"]Entity:GetForward()[/URL].
[lua]--Distance to spawn from base position local fwdOffset = 20 local upOffset = -40 local rightOffset = 5 --Entities local spawner = YourSodaMachine local newent = YourSodaCan --Get position and angles (actually 'normal' vectors) local spawnerPos = spawner:GetPos() local fwdDir = spawner:GetForward() local upDir = spawner:GetUp() local rightDir = spawner:GetRight() -- local positionOffset = Vector( fwdDir*fwdOffset, rightDir*rightOffset, upDir*upOffset ) local newPos = spawnerPos + positionOffset newent:SetPos(newPos)[/lua] Same thing but compact: [lua]newent:SetPos( spawner:GetPos() + Vector(spawner:GetForward()*20, spawner:GetRight()*5, spawner:GetUp()*-40) )[/lua]
[QUOTE=wh1t3rabbit;41074590][lua]--Distance to spawn from base position local fwdOffset = 20 local upOffset = -40 local rightOffset = 5 --Entities local spawner = YourSodaMachine local newent = YourSodaCan --Get position and angles (actually 'normal' vectors) local spawnerPos = spawner:GetPos() local fwdDir = spawner:GetForward() local upDir = spawner:GetUp() local rightDir = spawner:GetRight() -- local positionOffset = Vector( fwdDir*fwdOffset, rightDir*rightOffset, upDir*upOffset ) local newPos = spawnerPos + positionOffset newent:SetPos(newPos)[/lua] Same thing but compact: [lua]newent:SetPos( spawner:GetPos() + Vector(spawner:GetForward()*20, spawner:GetRight()*5, spawner:GetUp()*-40) )[/lua][/QUOTE] Looks very good, I'll try it later, and I'll tell you if it works :3 Thanks anyways for this useful reply. EDIT: It doesn't work, it spawns the soda can on the center of the entity.
Sorry, you need to Log In to post a reply to this thread.