Connect two hexagons by they walls using script

I have no clue how to connect these hexagons:

What i’m trying to achieve:

my problem is, what i’m thinking that the mesh part has a box size and it might be impossible to connect everything like that. not sure.

the model:
Hexagons.rbxm (6.9 KB)

(i need that to be done using script)

I don’t understand… What are you trying to do? Move them? Scale them? Only move one of them? Only scale one of them? Please, provide more details.

move one of them to the another’s wall, so they be connected

You could try creating points of interest on each side of the hexagon, and use their pivots to align them.

You could try creating a part to each side on both of these hexagons and make that part their root part. Then, once you need to put the hexagons together you can Hexagon1:PivotTo(Hexagon2.PrimaryPart.Position). Also, make sure that they properly welded to the RootPart

i was doing

local Room = workspace.r1
local PreviousRoom = workspace.r2

local prevDoorCF = PreviousRoom.Doors:GetChildren()[1].CFrame
local pivotToDoor = Room.PrimaryPart.CFrame:ToObjectSpace(Room.Doors:GetChildren()[1].CFrame)
local desiredPivot = prevDoorCF * CFrame.Angles(0, math.rad(180), 0) * pivotToDoor:Inverse()

desiredPivot = CFrame.new(desiredPivot.X, 5, desiredPivot.Z)

Room:PivotTo(desiredPivot)

everything was fine until i made it so that these rooms connected to other doors


Using :GetChildren()[index] is really not the best idea, if you add any other children to the room it will make the results unpredictable

i have no desired doors it can simply be just a random one, but i want to properly connect these hexagons

they look like regular polygons, so we only need their pivot at its center, and also we need the distance from the center to a door.

local room1 = workspace.r1
local room2 = workspace.r2

local doorDistance = 10
local whichDoor = 0 -- 0 - 5

local rotatedRelativePosition = CFrame.Angles(0, math.rad(60 * whichDoor), 0) * Vector3.new(0, 0, doorDistance)
local desiredPivot = room1:GetPivot() * rotatedRelativePosition
room2:PivotTo(desiredPivot)

local room1 = workspace.r1
local room2 = workspace.r2

local doorDistance = 10
local whichDoor = 0 – 0 - 5

local rotatedRelativePosition = CFrame.Angles(0, math.rad(60 * whichDoor), 0) * CFrame.new(0, 0, doorDistance)
local desiredPivot = room1:GetPivot() * rotatedRelativePosition
room2:PivotTo(desiredPivot)

change your distance . i don’t know your door distance

why do even whichDoor and doorDistance needs to be typed, the hexagon is split-part:


simple geometry. i made a mistake. it should be 2 times the door distance for the other hex’s center
but we can rename the variable to represent ‘centerToCenterDistance’

Bro made all that in 5 minutes


it’s not the thing i want

what i want:

then your original model has a 30 degree rotation offset (flat based vs angle based)
you can simply add 30 degrees to adjust for that
CFrame.Angles(0, math.rad(30 + 60 * whichDoor), 0)

did you rotate your other room? do not rotate


nope

you mixed up the Vector3 and CFrame types in the intermediate steps, here is the correct one

local room1 = workspace.r1
local room2 = workspace.r2

local centerToCenterDistance = 10
local whichDoor = 0 -- 0 - 5

local rotatedRelativePosition = CFrame.Angles(0, math.rad(rotationalOffset + 60 * whichDoor), 0) * Vector3.new(0, 0, centerToCenterDistance) -- notice this is CFrame * Vector3, result is Vector3
	local desiredPivot = room1:GetPivot() * CFrame.new(rotatedRelativePosition) -- notice this is CFrame * CFrame, meaning to just move the pivot, do not rotate
	room2:PivotTo(desiredPivot)
1 Like