Create an object at a random position with in limits

The game I am making is based on the old children’s song Five Little Ducks. The Player controls an adult duck looking for its ducklings.

When the player comes near the duckling the duckling follows the player using the magnetic extension.

The in game enemy is a small fox if the player is in collision with the fox The baby duckling is deleted.

I would like to have the duckling respawn at a random position so the player has to find it again.

I attempted to use this event

The problem is quite a few time the duckling has spawned inside a platform which makes it impossible to get it to follow the player.

Is there anyway to create the object randomly but not inside platforms or other obstacles

Any feedback greatly appreciated

I would question do you really need that kind of random limits
I would simply move duck or like add force to it if its in collision with platform
Other method would be to create multiple objects
Like for example you add object to your game called checker
You have it as red rectangle
You create like 200 of them or 100 or 50 using repeat event
At random in range X and Y
Now you delete all checker objects that are in collision with platform
And now you pick random checker and spawn duck on one of them
There is condition to pick random object
Now you just delete all checker objects

You could make checker red square but make it same dimensions as duck
Check does this method work and now you change checker to transparent/blank/empty image of same size no one see them yet they are there

1 Like

Para fazer seguir o jogador séria melhor usa" pathifing ", na minha opinião

Thank you the checker idea worked brilliantly

1 Like