Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to generate a cube out of smaller cubes?

Asked by 9 years ago

I would like to generate a large mass of blocks out of smaller blocks, for a building game to allow players to quickly add masses of parts (Why I want to make them out of smaller parts has to do with the way combat works) and the math on how to do this is lost on me.

I have been thinking of take the X Y and Z of a CFrame or V3 that the player enters and generating it like that in rows, but I do not even know how to spawn a part right beside another (almost like using a dragger tool to place the part at the exact position.)

Besides just compromising and making a different way of dealing damage so that the number of parts doesnt matter, how could I go about doing this?

(My math is atrocious due to a bunch of home life factors, so if you could explain the logic in laymans terms it would be very appreciated)

1 answer

Log in to vote
1
Answered by 9 years ago

Here's a small script that does what you want. There is a problem at Part.CanCollide = false. If you set it to true, the Parts don't line up as they should, but other than that, I think you're in the right direction with this script. Maybe someone else knows a way to bypass this.

local start = Vector3.new()
local blockSize = 2
local rowCount = 5

local posX = start.X
local posY = start.Y
local posZ = start.Z

local Model = Instance.new("Model", Workspace)
Model.Name = "Block"

for x = 1, rowCount do
    for y = 1, rowCount do
        for z = 1, rowCount do
            local Part = Instance.new("Part", Model)
            Part.CanCollide = false
            Part.Anchored = true
            Part.Position = Vector3.new(posX, posY, posZ)
            Part.Size = Vector3.new(blockSize, blockSize, blockSize)
            posZ = posZ + blockSize
        end
        posZ = start.Z
        posY = posY + blockSize
    end
    posY = start.Y
    posX = posX + blockSize
end
0
I think I can get around that by just using CFrames and welding it together, considering I want people to be able to CFrame parts together anyway. I think I can easily make this form rectangles and other shapes as well. Thank you for the help, I am terrible at math as stated in the OP! DonFeskeral 0 — 9y
0
The problem is CFrame, setting position messes stuff up if the parts can collide. iaz3 190 — 9y
0
In the future, please explain you code thoroughly instead of just posting it and saying "This works, try it" or something like it. Perci1 4988 — 9y
Ad

Answer this question