[Solved] How to check if an object is next to another object without using collision?

okay, i underestand now, thank you for your help, ill try your suggestion out and see if it works and get back to you with the result

okay so it stopped the first box when it got to the floor, but now i’m unsure of where to put the code that tells the game to spawn a new box

I tried this, but for some reason the box that hit the floor still has the currentBox variable set to true, despite me turning it off, as such I can still control it and the next box that spawns, the next box also doesn’t fall because all boxes are being picked and because one is touching the floor, it doesn’t add force

changed a few things up, tried a bunch of different stuctures, this is my current code. I am thoroughly stumped, as it seems that when the conditions for spawning a new box are met, the “ready” variable is set to true, but the “currentBox” variable is not being set to false or it is somehow being set back to true, but based on my understanding, that shouldn’t even be possible in this context.

Where it’s setting it to false currentBox is spelt with a lower case c

omg THANK YOU! figures it would all be because of a stupid typo.
I really appreciate everyone who helped me with this, I couldn’t have done it without you!

1 Like

okay, now that that problem is solved, i need to get back to original reason I made this question, stopping the player from being able to merge the current box into the already placed boxes, i tried this:

but that didnt seem to stop it from happening

EDIT: wait I realized why it isn’t working, its because its only checking if the boxes with “CurrentBox” active are colliding with eachother… unsure how to fix this tho

EDIT 2: realized that checking collision wouldn’t even work because if there was a box on the left, but not on the right, it would still stop the player from moving right. thinking of implimenting something similar to the way I detected if there was a box below me

You have not taken in what I wrote earlier. Please think about what you are doing. The first event filters the list of boxes down to 1 box. In that first subevent, you are checking for a collision between 2 boxes. But the list has only 1 box in it.

You are repeatedly checking for collision between 2 boxes, which won’t work because of the very first condition that filters the list to 1 box.

And even if that collision detection worked, which box is the action being applied to? The current one? The one that isn’t colliding with the current one? Or all of them?

What you are doing does not work, and will not work. Here’s how I would tackle it:

  1. duplicate the box objects in the editor, and give the duplicates the same name preceded with “Still_”.
  2. put these duplicates into a new object group named “StationaryBoxes”.
  3. when a box cannot move down any further, create a new box with the “Still_” name in the same position, and then delete the current box.
  4. when moving left, right and down, check for collision with StillBoxes and floor.

Using this method, you won’t need the CurrentBox boolean variable, because the only boxes object on the screen will be the current one.

1 Like

Okay first off, you’ll notice i made an edit where i did in fact realize that very thing. Please be patient with me im very new to Gdevelop and the selection thing is something im still getting used to.

Now then, your solution does seem like it may work, ill have to test it sometime later today. Thank you for your help, i do really appreciate it

1 Like

alright, followed your advice, worked well, it also removed the need for so many scene variables
heres the finished falling code

however, a new problem has arisen. I can’t use collision to check if the player can move left and right, as if a collsion was detected on the right, but not on the left, the player would be unable to move either way.
my solution is to use the same method I used for determining if there is a box beneath the current box, having a point on either side (I’m probably going to need 3 points on each side, one for the middle and one for each corner, but I’ll get there when i get the middle point working.) to accomplish this, i have implemented the following code

but for some reason when i load up the scene it is detected that the points are inside a staticBox, even though no StaticBoxes are present in the scene and i am unable to move the box left or right at all, why is this happening?

okay so after testing for a bit it would seem that after i let the first box land and create a static box, the next box spawned was then able to move left and right. possibly because it was checking against something that didn’t exist it was causing an error maybe? unsure. so I added a random static box off screen, which allowed the boxes to move left and right from the start, but it still didn’t stop the box from moving left or right when one of the points entered a static box on the respective side. so once again, I am stuck

You don’t need that Pick all StaticBoxes condition unless you have a parent condition that filters StaticBoxes. Otherwise all StaticBoxes in the scene are taken into consideration.

My way of doing the right move would be:

yeah I kinda figured, the pick all objects was really just put there to test if that would change anything, which of course, it didn’t

it took me a minute to figure out you had turned “ignore edge collisions” on, but yeah that actually works really well. ironically I had just figured out a way to make my method work, but your method is far simpler. thank you, my problem at long last, has finally been solved, i really appreciate your help, hopefully i don’t get stuck on something this simple again

for anyone who comes here in the future looking for a solution, here is the completed code


Thank you for sharing your solution. My only suggestion to your events is that the Boxes distance to Boxes is not needed:

Ah, right i need to update that to check for static boxes. Been so focused on the rest of my code that i forgot about that