Bug with object checking its neighboring grid cells

Before proceeding, please use the forum search feature at the top of the page to check if your question has already been answered.

How do I…

I’ve got a game where these block objects need to check up, right, left and down to see 1) if there is a block adjacent to them, 2) if there is a block there what type of block is there. I’m using raycasting from each block object instance on the scene, but I’m having some trouble getting it to work.

Right now, its outputting “empty” or “” in the debug menu in the object array which stores any given block’s knowledge of what is in the 4 orthogonal squares around it. It’s not setting the right array children to “empty” and it also isn’t setting childs to the ObjectName() of the block that is there.

I’m not totally sure what’s going wrong, but its probably something with object picking cause it usually is with Gdevelop lol.

[Note: I’m using an ID system to help pick objects, each object has a unique ID number]

That doesn’t explain a lot, sorry. it’s hard to explain.

Help would be much appreciated!

Related screenshots

The red is the blocks (not very good at art)

Right now the top block is outputting:

And the bottom block is outputting:

Let me know if you have any questions.

Never cast a ray from SOME object
Against object that is same object or in same group from its center
Cause think like this
You are knight i am knight
We gonna cast a ray from your center toward angle 90 against knight
NOT another knight but against knight
If we do it from center of your body
Then ray is already inside knight cause its inside of you

Also idk how inverting raycast work

FINALLY
You should cast from beyond object for example

Cast ray from cube.CenterX()+cube.Width()
And now ray starts beyond cube from which it starts raycasting

BUT better idea would be to check if point is inside of object

cube.CenterX() + cube.Width() ; cube.CenterY() is inside cube
Also i have no idea why you use repeat for each block and also pick all block
That makes no sense
I think you built a lot of logic without testing it on each step does it work
And now you have problems cause of that