GameMaker Studio 2 Desktop

GameMaker Studio 2 Desktop

Need help with randomly spawning objects
Alright, so I figured out how to randomly spawn objects within basically a square area in which I want them to spawn, as well as how to trigger a spawn and control the rate at which they spawn at. My issue I'm running into is that since I have no speed or movement of any kind on these objects, that they keep spawing on top of each other.

What I'm doing is literally spawning in blocks for a player to destroy which are 32x64 pixels in size and upon a block being destroyed a new one spawns in but the location of where it spawns within the room is "random". (or as random as "spawn between point A and point B" can be)

What I'm trying to figure out is how to make the blocks still spawn in with the specifications I've already given them, but not have them overlaying eachother.

also, I am working with obj_block1 and obj_block2 (2 objects made for my project) so if I could learn how to avoid both objects spawning on top of not only themselves but eachother that would be awesome as well.

I know that the answer is along the lines of
"if object A spawns on top of object B or self, delete newly created object"
or
"Do not allow object a to spawn on top of object B or self"
However as I am still quite new to both GML and the DnD system I am not yet aware of how to use GMS to the best of what I know it is capable of as yet.

~~~~~~~~~~~~~~~~~~~~~

On a seporate note, I am also having issues with a "bouncing ball" machanic.
It's not made sence to me but for some reason the balls don't always "bounce" as they are meant to. I have it set to where if a ball comes in contact with my wall that it would bounce off of it. I guess it doesn't always bounce off the wall or something, because it tends to phase through and get stuck within the wall sometimes or if I leave the room running for too long.
Due to how the room is constructed I do plan on rebuilding the wall with animated holes that the balls can go through, but as it stands there are no holes for them to do so within and yet they somehow find a way to do so anyway.
Legutóbb szerkesztette: Rejomei; 2018. júl. 2., 14:52
< >
12/2 megjegyzés mutatása
When you spawn the block check if it's not touching another block. Else destroy itself and create another.

Create event:
if place_meeting(x, y, obj_block)
{
// your code to spawn another block
instance_destroy();
}

Or you can try move the block until it's not colliding anything

Create event:
while(place_meeting(x, y, obj_block))
{
x = random_range(// horizontal limit of the spawn area)
y = random_range(// vertical limit of the spawn area)
}

Or check if there is nothing before you create the block

Block spawner:

var xx = random_range(// vertical limit of the spawn area)
var yy = random_range(// vertical limit of the spawn area)

if place_free(xx, yy) instance_create(xx, yy, obj_block)

Legutóbb szerkesztette: maras; 2018. júl. 2., 14:56
marasovec eredeti hozzászólása:
When you spawn the block check if it's not touching another block. Else destroy itself and create another.

Create event:
if place_meeting(x, y, obj_block)
{
// your code to spawn another block
instance_destroy();
}

Tyvm, this one seems to have gotten the results I was looking for :D
I was pretty sure that it was along the lines of something like this.

Had to edit my spawning code a little to avoid errors that would lead to auto crashing the game upon destroying one of the blocks, but they are now only spawning within pixels of each other and no longer touching :D
< >
12/2 megjegyzés mutatása
Laponként: 1530 50

Közzétéve: 2018. júl. 2., 13:51
Hozzászólások: 2