Random spawn of objects, with restriction

Hi! I made my game so that objects spawn on the screen in random places, within a certain rectangle. How do I make the objects spawn in the same random places of this rectangle, except for certain small areas where I have water or fire, for example? I’ve used collisions, but it’s not very pretty.

What do you mean not very pretty?

Can you give a screen shot as an example of what you mean? And a screen shot of your events that spawn the objects.

The spawn object appears in a forbidden place for a short time, and only then appears in a permitted place

You can rework your spawn object to use a invisible sprite to check for collisions first.
If sprite is colliding with kamen2 or water, change its X and Y position.
Below that should be your normal spawn object event.

What you are doing is checking the collision once per frame. You should check for a collision and reposition in a loop, until there is no longer a collision, so it happens in one frame. This will prevent the object appearing in a forbidden position for a short period of time.

First place the object, and then using a while the collision is true, change the position of the object.

2 Likes

I didn’t understand what it means “First place the object”. I did so, but it didn’t help.

Like this:

First event places the object. Then in the second event the while repositions it while it’s in collision with another object.

1 Like

Forgive me for my stupidity, but what am I doing wrong?

My first 3 thoughts are:

  1. Put all the objects the food1 can collide with into an object group, and check for collision with that group name.
  2. you have 2 tweens with the same name on an object, and you didn’t remove the first tween before you started the second.
  3. That delay between the colour tweens may be having an impact. I suggest you remove the wait and the second tween. Instead, have a standalone event that checks if the object tween has finished, and in the actions removes it and starts the second one:
1 Like

How difficult it all is for a beginner. I will study it. Thank you very much for your attention to my problem)

The problem was due to the improper use of the twin. Now everything is beautiful. You’re a genius!

1 Like