Need help spawning characters on a grid

I am trying to make a game where you get materials to create characters which generate more materials. it’s kinda laid out like a “merge” type game where the character are set on a grid. (each black and white tile is a slot on the grid)

So at some point in the game I want there to be a button, and when you press it a character appears on the grid. But it has to make sure not to spawn ontop of another character.

I have put each character in a group so that I dont have to set a function for each individual one and I also made a sprite for each slot on the grid and put it into its own group (I know it’s not the best way to do it but it’s the best I could think of)

Here is my code which I thought would work:

After playing the game it just piles all the characters it spawns in the top left slot

I’m doing something wrong but im not sure what so if anyone has any ideas then i’d appreciate it :slight_smile:

thank you for reading!

It looks like you’re using x twice in your Create object. It should be x and y. Make sure the characters collision mask isn’t in collision with multiple tiles unless you want more than 1 marked as occupied. You might need to shrink the character or adjust its hitbox.

1 Like

thank you for pointing out my X Y mistake! i dont know how i missed that but unfortunately it didnt solve the problem D:

While not optimal, this tests your concept. This works for me. Make sure all objects are in their respective groups. Note the order of the objects in the first collision doesn’t seem to matter but the order in the second inverted collision does. It adds an object based on the way the objects were added to the scene, IDK your plan. You could add pick a random object after the Boolean check that adds the objects.

1 Like

adding the pick random object they seem to spawn on some of the other tiles but they still seem to pile up in that one spot in the top left for some reason

hold up… they actually seem to be spawning diagonally??

Did you fix your x,y?

This works for me. I added a hue action to change the tiles to make sure it was working.

Click the button to add. The circles are draggable for testing.

1 Like

i fixed the x,y and they now appear on random tiles but still seem to be stacking and mainly in the top left still. this is confusing

nvm I found out the issue is the size of the characters. The actual image of the character covers 2 tiles in height (the collision of the characters only cover 1 tile) but when I change them to half their size it works completely fine which is not what i want sadly.

im not sure if this problem ties into the original problem?

1 Like