• Spawning props with no collision?
    6 replies, posted
I've been trying to figure this out for a bit now. I found this lua code online on here I think. function SpawnProps() SpawnProp(Vector( 897.13, -406.16, -432.97 ), "models/chairs/armchair.mdl") end hook.Add("InitPostEntity","SpawnTheProps",timer.Simple(1,SpawnProps)) function SpawnProp(position, model) local ent1 = ents.Create("prop_physics") local ang = Vector(0,0,1):Angle(); ang.pitch = ang.pitch + 90; print("Prop spawned with model: " .. model) ang:RotateAroundAxis(ang:Up(), math.random(0,360)) ent1:SetAngles(ang) ent1:SetModel(model) local pos = position pos.z = pos.z - ent1:OBBMaxs().z ent1:SetPos( pos ) ent1:Spawn() end I have been using it and it works but I can't figure out how to spawn the chair without collision. I'm very bad at coding so any help would be appreciated. :)
[url]https://wiki.garrysmod.com/page/Entity/SetCollisionGroup[/url] ent1:SetCollisionGroup(COLLISION_GROUP_WORLD)
@Sestze Thank you so much. Where do I put this in the code? I have managed to find that too put every time i put it in it didn't work.
Well, not sure if it matters if it's pre or post :Spawn(), my code usually has it after.
@Sestze Do you think you could paste it where it should go? It's not working for me :/
function SpawnProp(position, model) local ent1 = ents.Create("prop_physics") local ang = Vector(0,0,1):Angle(); ang.pitch = ang.pitch + 90; print("Prop spawned with model: " .. model) ang:RotateAroundAxis(ang:Up(), math.random(0,360)) ent1:SetAngles(ang) ent1:SetModel(model) local pos = position pos.z = pos.z - ent1:OBBMaxs().z ent1:SetPos( pos ) ent1:Spawn() ent1:SetCollisionGroup(COLLISION_GROUP_WORLD) end alternatively, we can use phys:EnableCollisions(false) function SpawnProp(position, model) local ent1 = ents.Create("prop_physics") local ang = Vector(0,0,1):Angle(); ang.pitch = ang.pitch + 90; print("Prop spawned with model: " .. model) ang:RotateAroundAxis(ang:Up(), math.random(0,360)) ent1:SetAngles(ang) ent1:SetModel(model) local pos = position pos.z = pos.z - ent1:OBBMaxs().z ent1:SetPos( pos ) ent1:Spawn() local phys = ent1:GetPhysicsObject() if(phys and phys:IsValid()) then phys:EnableCollisions(false) end end Not sure why it wouldn't be working if it ISN'T working.
@Sestze Thank you so much [B]IT WORKS :D[/B] Now I need one more favor. How would i make myself the parent so I can attach it to me. I was only able to do this with the single player console can't figure it out in lua. :/ function SpawnProp(position, model) local ent1 = ents.Create("prop_physics") local ang = Vector(0,0,1):Angle(); ang.pitch = ang.pitch + 90; print("Prop spawned with model: " .. model) ang:RotateAroundAxis(ang:Up(), math.random(0,360)) ent1:SetAngles(ang) ent1:SetModel(model) local pos = position pos.z = pos.z - ent1:OBBMaxs().z ent1:SetPos( pos ) ent1:Spawn() ent1:SetCollisionGroup(COLLISION_GROUP_WORLD) ent1:SetMoveType( MOVETYPE_NONE ) ent1:setparent( Entity parent, number attachmentId=-1 ) end ent1:setparent Is still default. I got it from [url]https://wiki.garrysmod.com/page/Entity/SetParent[/url] Thank you for helping :)
Sorry, you need to Log In to post a reply to this thread.