Making map "segments" connect to each other

Hey! So I’ve been having a problem for a while now and I was wondering if anyone could maybe help me out!

So what I’ve been trying to do is make randomly generated map segments line up perfectly (so they create a perfect path) like in the picture:

But it ends up looking like this:

My idea was to make 2 parts (each segment has a start and an end part) overlap (so newSegments startPart overlaps with previous segments end pos)


Bildschirmfoto 2024-10-24 um 13.21.57
(Green being the “NextPos” (pos where next tile should go))

Here’s my code:

if previous then
		local previousModel : Model = previous

		local function ModelSnap()
			local previousNextPos : BasePart = previousModel.PivotPoints:FindFirstChild("NextPos")
			local selectedLastPos : BasePart = newSegment.PivotPoints:FindFirstChild("LastPos")
			
			newSegment.PrimaryPart = selectedLastPos
			newSegment.WorldPivot = selectedLastPos.CFrame
			
			newSegment:PivotTo(CFrame.new(previousNextPos.Position))
		end

		ModelSnap()
	end

(If you are wondering, corner tiles look like this:)

Hope someone can help me :smiley:

You could setup attachments on each of the tiles to help connect them.

Yea but wouldn’t that cause the same issue as when I’m using parts?

Again, help would be GREATLY appreciated (I’ve been having this issue for weeks now)

Assuming those paths are models, you could scrap the part thing and create attachments at the end of each model and also edit the pivot of the models, then you could simply change the models location to the attachment’s and have it work because of the pivot. And for the colliding issue I guess you could add a invisible hit box to when the next path is being generated, and detect if it hit anything you don’t want it to hit, and if it does you can regenerate a random path and check again if it colliding or not, keep doing that until you get a path that doesn’t collide .

just to be clear the pivot would be set to the start of the model and the attachment would be placed at the end

Ah? I doubt the colliding is necessary bc the segments are all 21x21 squares but the other idea sounds good.

I didn’t quite understand how I should set the attachments and pivots though.

1 Like

Alright then. For the pivot thingy you can create an attachment at where the NextPos would be at ( the center of NextPos ) and change the model’s pivot to be placed at where the endPos would be at ( center of endPos ) and after doing that, teleporting the model to the exact position of the attachment would connect the two models

I’m pretty sure you could fix it by making sure the green and white parts are both halfway clipping into the segment, also these exposed bits
image
are probably caused by one of your parts facing the wrong direction
are caused by this line removing the angle of the part it’s trying to snap to

newSegment:PivotTo(CFrame.new(previousNextPos.Position))
-- this should fix it:
newSegment:PivotTo(previousNextPos.CFrame)

edit: this is what I mean by making sure your parts are halfway clipping

It didn’t work :(. I just caused all segments to be on top of each other (the pivotTo(cframe) line)

It kinda worked. The rotation is just messed up still. Any ideas?

RobloxStudioBeta_VU2CFp6qoA

I’m not sure how you’ve set things up on your end, but on mine it works fine.
Path gen.rbxm (5.1 KB)
^ feel free to base yours off this if you want

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.