3D: Detecting an object in position as a condition

Screencast from 2025-04-05 12-27-01

So I’m making the game above, where tiles can be placed on the side of existing blocks. However, I’m having trouble detecting whether there something occupying the space before placing the block.

Each space is 64 x 64 x 64, so I basically don’t want to place two objects in the same space.

How do I…

How do I detect that the space is empty when placing? I’ve tried raycasting (I’m using raycasting to get the right position initially), but I can’t seem to figure out raycasting from what position to the empty space. What compounds the issue is that I’m placing the same objects that I’m trying to detect, so I can’t really use the usual detection methods.

What is the expected result

If space is empty: place tile/block.
If space is occupied: don’t

What is the actual result

Always placing blocks.

Related screenshots


I haven’t finalised all the conditions for each direction. The game starts at -90 degrees, and the player can rotate the camera 90 degrees at a time.

Thanks in advance.

Okay so I figured out a system that works for me. It involves a structure of arrays that gets updated with the z-level and coordinates every time I place a tile, and then when I place a new tile, these are checked first to see if they are in the structure.


Screencast from 2025-04-05 18-03-44

1 Like

Hi!

An another idea would be to place by advance many objetcs invisible.
In cas of collision with these, no placement of your visible blocs.

A+
Xierra54

Hey my Amigo, that is exactly what I did after posting haha.

I actually had it set up this way before, but I was getting stuck with guide tiles getting placed over the actual tiles, so after I implemented the above approach, I was able to reimplement this with proper tile detection. Plus now the player can place at any angle.

Happy to see that!

In fact and i think you rectified that, we must read my sentence in inverse order.
My sentence should be :+1:
“In case of collision with invisible blocs, you can place real visible blocs”

A+
Xierra54