Rotate part with parent

Hello i am creating a grid, based on the parent part…
My parts spawn on top of the main part but now i cant get it to account for rotation…
this is original
image
this is oritented…
image

function CreateGrid()
    local gridSizeX = math.ceil(v.Size.X / nodeDiameter)
    local gridSizeZ = math.ceil(v.Size.Z / nodeDiameter)
    part.Size = Vector3.new(nodeDiameter, part.Size.Y, nodeDiameter)
    local bottomLeft = Vector3.new(v.Position.X-(v.Size.X/2), v.Position.Y, (v.Position.Z-(v.Size.Z/2))) 
    for x = 1,gridSizeX, 1 do
        Grid[x] = {}
        for z = 1, gridSizeZ, 1 do
            local WorldPoint = bottomLeft + Vector3.new(1,0,0) * (x * nodeDiameter + nodeRadius) + Vector3.new(0,0,1) * (z * nodeDiameter + nodeRadius) - part.Size
            local min = WorldPoint - (((nodeDiameter + nodeRadius)) * part.Size)
            local max = WorldPoint + (((nodeDiameter + nodeRadius)) * part.Size)
            local mypart = part:Clone()
            mypart.Position = Vector3.new(WorldPoint.X, v.Position.Y + 5, WorldPoint.Z)
            mypart.Parent = workspace
        end
    end
end

Was wondering if someone could give me some small support.

Seems i am using the larger box for the filling of position…
image

How can i use the actual part bounds?

What you want to do is use CFrame instead of Position to orient the grid parts. This accounts for rotation instead of just positions based off of the part’s size.

So how would i create a world position of CFrame? and increase it to fill up the main part?

local WorldPoint = bottomLeft + Vector3.new(1,0,0) * (x * nodeDiameter + nodeRadius) + Vector3.new(0,0,1) * (z * nodeDiameter + nodeRadius) - part.Size

I’m going to write some code to help you out, but in the mean time I suggest looking at this: CFrames | Documentation - Roblox Creator Hub

I kind of undertand what CFrames are and how to use them just a little bit.

I read that up tbh, I’ve had some experience with CFrames, clearly not enough to apply it to what i need here. Appreciate the attention, I feel the parts beign created for the grid is using the outer box of the bounds to calculate its position, im not sure how to use that to apply cframe math

Managed to get slightly better results…

function CreateGrid()
	local gridSizeX = math.ceil(v.Size.X / nodeDiameter)
	local gridSizeZ = math.ceil(v.Size.Z / nodeDiameter)
	part.Size = Vector3.new(nodeDiameter, part.Size.Y, nodeDiameter)
	local bottomLeft =  v.CFrame * CFrame.new(-v.Size.X / 2, 0, -v.Size.Z / 2) --Vector3.new(v.Position.X-(v.Size.X/2), v.Position.Y, (v.Position.Z-(v.Size.Z/2))) 
	for x = 1,gridSizeX, 1 do
		Grid[x] = {}
		for z = 1, gridSizeZ, 1 do
			local WorldPoint = v.CFrame * (bottomLeft + Vector3.new(1,0,0) * (x * nodeDiameter + nodeRadius) + Vector3.new(0,0,1) * (z * nodeDiameter + nodeRadius) - part.Size)
			local min = WorldPoint - (((nodeDiameter + nodeRadius)) * part.Size)
			local max = WorldPoint + (((nodeDiameter + nodeRadius)) * part.Size)
			local mypart = part:Clone()
			
			mypart.Position = Vector3.new(WorldPoint.X, v.Position.Y + 5, WorldPoint.Z)
			mypart.Parent = workspace
		end
	end
end

It kind of works now… but not the best…


https://gyazo.com/d7a9a7a2c91328b8b26d53537ea81e43

function CreateGrid(v)
	local part = workspace.Unwalkable.GridPart:Clone()
	part.CFrame = v.CFrame
    local gridSizeX = math.ceil(v.Size.X / nodeDiameter)
    local gridSizeZ = math.ceil(v.Size.Z / nodeDiameter)
    part.Size = Vector3.new(nodeDiameter, part.Size.Y, nodeDiameter)
    local bottomLeft = v.CFrame * CFrame.new((-v.Size.X / 2) - nodeDiameter, 0, (-v.Size.Z / 2) + nodeDiameter)

    for x = 1,gridSizeX, 1 do
        Grid[#Grid + x] = {}
        for z = 1, gridSizeZ, 1 do
            local WorldPoint = bottomLeft * CFrame.new((x * nodeDiameter + nodeRadius + 1),0,(z * nodeDiameter + nodeRadius - 1)) - part.Size
            local min = WorldPoint - (((nodeDiameter + nodeRadius)) * part.Size)
            local max = WorldPoint + (((nodeDiameter + nodeRadius)) * part.Size)
            local mypart = part:Clone()
            mypart.Position = Vector3.new(WorldPoint.X, v.Position.Y + 5, WorldPoint.Z)
            mypart.Parent = workspace
        end
    end
end