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

Information on grid placement systems? [Solved]

Asked by
AZDev 590 Moderation Voter
6 years ago
Edited 6 years ago

I know about rounding the position of the object to the nearest unit. I don't want to use that because it becomes inaccurate with different size objects.

I'm wondering how I would go about creating a grid placement systems that can be used on both models and individual parts.

If I have a part that is exactly 1 × Y × 1 studs, it would snap to the center of the nearest stud. That is possible using the rounding method.

If I have a part that is exactly 4 × Y × 4 studs, it would snap to the center of the nearest 4 studs. If I use the rounding method for this case, the part will snap to the nearest stud. That puts the center of my object at X.5 × Y × Z.5.

If someone could point me in the right direction here, I'd really appreciate it.

Thanks!

0
Seems kind of hacky but I just thought of something. AZDev 590 — 6y
0
If the resulting position is a decimal, I could add to the decimal to make it a whole number. AZDev 590 — 6y
0
I know this question is already answered, but if I understand it right, if you have a part at so you want it to snap to a multiple of 4, so, 0, Y, 0, then 4, Y, 4, then 8, Y, 8 and so on, so both 13.758 and 10.962 would snap to 12, right? Well, that very easy, divide the current position by the # you want (4 in this case), round it to the nearest whole #, and then multiply by 4 again RiskoZoSlovenska 378 — 6y
0
I know this question is already answered, but if I understand it right, you want it to snap to a multiple of 4, so, 0, Y, 0, then 4, Y, 4, then 8, Y, 8 and so on, so both 13.758 and 10.962 would snap to 12, right? Well, that very easy, divide the current position by the # you want (4 in this case), round it to the nearest whole #, and then multiply by 4 again. Lets take 13.758. Divide by four:    RiskoZoSlovenska 378 — 6y

1 answer

Log in to vote
0
Answered by
AZDev 590 Moderation Voter
6 years ago

Found the solution!

local MousePos = Mouse.Hit.p
local X = math.floor(MousePos.X)
local Y = 0.5
local Z = math.floor(MousePos.Z)

workspace.Part.CFrame = CFrame.new(X, Y, Z)

local PartPos = workspace.Part.Position
local newX = PartPos.X
local newZ = PartPos.Z
if (math.fmod(PartPos.X, 1) == 0) ~= true then
    local Decimal = math.fmod(PartPos.X, 1)
    local newX = PartPos.X + (1-Decimal)
elseif (math.fmod(PartPos.Z, 1) == 0) ~= true then
    local Decimal = math.fmod(PartPos.Z, 1)
    local newZ = PartPos.Z + (1-Decimal)
end

PartPos = Vector3.new(newX, Y, newZ)

workspace.Part.CFrame = CFrame.new(PartPos)
Ad

Answer this question