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

Brick Placement On A Stud Grid?

Asked by 6 years ago

So here is a script I sort of modified and I want to know how to make the bricks be placed on a 1 stud instead of using no grid. Below is the script.

tool = script.Parent

function click(mouse)
    local part = Instance.new("Part")
    part.Position = mouse.hit.p
    part.Parent = game.Workspace
    part.Anchored = true
end

function selected(mouse)
    mouse.Button1Down:connect(function () click(mouse) end)
end

tool.Selected:connect(selected)

1 answer

Log in to vote
4
Answered by
Bellyrium 310 Moderation Voter
6 years ago

ill try to explain the best I can! Reply if you need me to clear something up.

So the basics behind what you want to do is simple! Lets say hypothetically that mouse.Hit.p == 0.1, 0.5, 0.9

Knowing that math.floor( NUMBER ) returns NUMBER rounded down, always down.

So if you took each offset value of mouse.Hit.p and added 0.5 to it, then round it down. You would have the closest whole number.

Local Pos = Vector3.new( math.floor(mouse.Hit.p.X + 0.5),math.floor(mouse.Hit.p.Y + 0.5),math.floor(mouse.Hit.p.Z + 0.5)) -- as an example 
0
When you say Pos, does that refer to position? BunnyFilms1 297 — 6y
0
Never mind! I got it working! Thank you for the help! BunnyFilms1 297 — 6y
0
How would I change the X and Z grid to 2 studs? BunnyFilms1 297 — 6y
0
I believe you would divide the position of the mouse by 2, add 0.5 again (because it rounds down automatically), then multiply that by 2 again! Bellyrium 310 — 6y
View all comments (2 more)
0
I did it but all it does is offset where the brick is placed. Here is what I wrote: local Pos = Vector3.new( math.floor( mouse.Hit.p.X /2+0.5*2),math.floor(mouse.Hit.p.Y + 0.5),math.floor(mouse.Hit.p.Z /2+0.5*2)) BunnyFilms1 297 — 6y
0
you haveto remeber BEDMAS Brackets,exponents,division,multiplication,addition subtraction. (mouse.Hit.p.X /2+0.5*2) should be ((mouse.Hit.p.X /2+0.5)*2) Bellyrium 310 — 6y
Ad

Answer this question