Random Spawning of instances without overlapping

H

HarryMG

Guest
Hi all, so I am creating a vertical infinite scroll platformer, to have an "infinite effect" , I have set a vertical speed to instances that will randomly spawn, however I still do not have any ideas how to achieve a random spawning of the instances that are not overlapping, there are 3 instances that will spawn, a short, medium and long lines. How can I make them spawn that they are not overlapping? Thanks!
 
A

Aura

Guest
Welcome back @HarryMG!

Check if the place is empty before spawning with the help of place_empty() or move to a random new position if a collision is detected.
 
X

Xskode

Guest
Hi all, so I am creating a vertical infinite scroll platformer, to have an "infinite effect" , I have set a vertical speed to instances that will randomly spawn, however I still do not have any ideas how to achieve a random spawning of the instances that are not overlapping, there are 3 instances that will spawn, a short, medium and long lines. How can I make them spawn that they are not overlapping? Thanks!

there are a few ways of achieving such.

in Object that's spawning lines
Code:
randomize();
var ranx = random(view_wview[0]);

///asuming you have no limits on your y location for random spawning
var rany = random(view_hview[0]);

if place_free(ranx, rany)
   {
      instance_create(ranx, rany, obj_spawned);
   }
else if !place_free(ranx, rany)
   {
     do
       {
          var ranx = random(view_wview[0]);
          var rany = random(view_hview[0]);
       }
     until (place_free(ranx, rany));

   instance_create(ranx, rany, obj_spawned);
   }
this will working if
  1. you are using views
  2. the spawning objects are solid
this will stop spawning objects from overlapping any solid objects

is this what you were looking for?
 
Top