• Find a suitable spawning position for an entity
    2 replies, posted
Hey everyone. I was wondering if is a way to spawn an entity in a random location without it spawning in a wall or in the air? Here's my spawning code so far: [CODE]local function SpawnBuks() local x = math.random(-13000, 13000) local y = math.random(-13000, 13000) local z = math.random(-11000, 513) local ent = ents.Create( "bluebuk" ) if ( !IsValid( ent ) ) then return end // Check whether we successfully made an entity, if not - bail ent:SetPos( Vector( x, y, 513 ) ) ent:Spawn() ent:Activate() local phys = ent:GetPhysicsObject() if ( IsValid( phys ) ) then phys:EnableMotion(true) phys:Wake() end end[/CODE] Any help is appreciated :v:
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/navmesh/GetAllNavAreas]navmesh.GetAllNavAreas[/url] Requires navmesh for the map (mapname.nav) table.Random + GetPos. That would be simple one, you could also make checks that its accessible and not underwater etc.
Thanks!
Sorry, you need to Log In to post a reply to this thread.