Find out if newly placed tiles are joining previously placed ones

I have a simple setup where the user can place down tiles and they snap to position like they are on a grid. However I’m trying to find out if there is already a tile placed in a next to it, I want it so the user can only place a tile as long as its joining another. What would be the best approach? Thank you

“I have a simple setup where the user can place down tiles”

i have no idea what that means. what controls does this use? mobile touch screens, PC mouse, VR Motion controls, or xbox gamepad? do they drag n drop a tile from a palette? or do they choose a tile from a palette then click a location to place it? is there a character that needs to walk up to a location? or some kind of tile placing bounding box cursor? or a crosshair like a first person shooter?

My bad sorry. It’s using the top down controller and the user places it down by mouse click.

can they place tiles in 3 dimensions? or only a flat plane?

Only on the x and y axis, the z is locked to 0 so yeah kind of a flat plane

for detecting adjacent tiles on a 2D plane, you can use 2 sphere traces, 1 with a radius large enough to hit the surrounding tiles, and the other with a radius small enough to only hit 1 tile. when a player clicks on the floor (which may be invisible or not, but should have collision to detect clicks), you can convert their mouse location to world space, snap that location so its centered on your tile, then shoot 2 sphere traces straight down to the center of the tile. if the large sphere trace finds a blocking hit, and the small sphere trace does not, spawn a tile, otherwise, do nothing.

91476-2016-05-22_13-09-04.png

This is what kind of view im looking at, the blue squares are starting points, and the sand coloured ones are moved around by mouse until they are left clicked into position. Im going to give your advice a go although i have one question, it would constantly need to be checking is there is a path next to it while the player is dragging around the square, wouldnt sphere traces cause a perfomrance issue if they was on every tick? Either way thank you for your help :slight_smile: sorry for the delayed reply!

sphere traces are extremely cheap, and they are often used every tick in code for movement components or to keep a characters feet on the ground. you will not notice any performance penalty, from a few traces every tick.

imagine destroying a destructible mesh statue, which breaks into 50 pieces. every piece would be doing collision traces every tick, as well as a lot of physics code. now imagine how many of these statues it would take to make a modern game slow down, then realize you are just doing 2 traces and no physics calculations. it won’t affect performance.

The sphere trace worked like a charm! Ive now set up a system that can only build a path when one is linked to it, just as needed! Thankyou :slight_smile: