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

How to make a Grid placement system?

Asked by 6 years ago

I have put this code in a local script in starterpack:

local mouse = game.Players.LocalPlayer:GetMouse()
local moveModel = workspace:WaitForChild("RockFloor")

-- don't detect the model we're moving
mouse.TargetFilter = moveModel

function placeAtMouse()
    -- make sure the mouse is pointing at something
    if mouse.Target then
        -- where we cast our ray from (shifted slightly up so the ray will hit the surface we're hovering)
        local origin = mouse.Hit.p + Vector3.new(0, 0.1, 0)

        -- cast our ray and get our normal, which is a unit vector
        local ray = Ray.new(origin, Vector3.new(0, -1, 0))
        local hit, pos, normal = workspace:FindPartOnRay(ray, moveModel)

        -- get the perpendicular vector and the angle between the two
        local cross = Vector3.new(0, 1, 0):Cross(normal)
        local angle = math.asin(cross.magnitude) -- division by 1 is redundant

        moveModel:SetPrimaryPartCFrame(
            CFrame.new(mouse.Hit.p + normal * moveModel:GetModelSize().y/2) -- position
            * CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle) -- angle, cross must not be Vector3.new()
        )
    end
end

-- check every frame
game:GetService("RunService").RenderStepped:connect(function()
    placeAtMouse()
end)

But i wonder how i can actually place the blocks and make them align in a 12x12x12 grid. (like in minecraft)

0
i could help you on this if you still need help! as im currently make a tycoon game with a simular system popgoesme700 113 — 5y
0
yes please i need help with that ariaaa3r3 -52 — 3y

Answer this question