If overlapping/something already there

00george

  • Posts: 161
Hi I have some actors that are generated and I was wondering if I could create a behaviour that if I was generating a actor and where it was being generated there was already a actor so they were like overlapping It could delete the actor thats already there. So if its hard to undertand.

00george

  • Posts: 161
Bump (Are we allowed to bump?)

theabbott

  • Posts: 271
So you'll want to make a list attribute to store the region of actors when they're created,

then some logic to say:

If actor is already in region

Kill actor in region

Spawn new actor in region


I had a similar problem with trying stop spawning in the same place, maybe that will help you:

http://community.stencyl.com/index.php/topic,9144.msg56320.html#msg56320

Innes

  • *
  • Posts: 1960
There are usually a number of different ways of achieving the same result. I would base my advice on how many of these actors were on screen, and how fast they were being generated.

It would also depend on whether or not the actors were 'physics objects'; for example, If an 'active' physics object is created over the top of an existing physics object, I am fairly sure that they would 'ping' apart from each other instantly.

To avoid the above physics problem, I can think of two options off the top of my head...

1) Create a sensor (the same size as the actor) where the new actor will be positioned, and if the sensor collides with the existing actor type, kill the actor, then kill the sensor and create the new actor.

2) Do something similar with a zone: Create a zone (same size as the actor) and check if an actor 'enters' the zone (i.e. it is overlapping). If it is overlapping, then kill the actor, remove the zone, and place the new actor.

If the actors are not physics objects, then you could simply check the XY coordinates to see if the new actor would overlap an existing actor, using a For loop to loop through the position of each actor of that actor type. I imagine a custom block would be the neatest way to achieve this.

I haven't tried any of the above, but that's what springs to mind in the first instance.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.