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

Why this grid placement system code only works on specific baseplate size?

Asked by 2 years ago

So I made this grid placement system thingy and the block keep floating, so i decided to change the baseplate size and then it somehow works

The code:

local Player = game.Players.LocalPlayer
local plrChar = Player.Character
local mouse = Player:GetMouse()

function SetUp()
    local NewBlock =  script.Part:Clone()
    NewBlock.Parent = workspace
    NewBlock.Transparency = 0.5
    NewBlock.CanCollide = false
    return NewBlock
end

local Thing = SetUp()

function Round(Input, GridSize) 
    local X = math.floor(Input.X / GridSize + 0.5) * GridSize 
    local Y = math.floor(Input.Y / GridSize + 0.5) * GridSize 
    local Z = math.floor(Input.Z / GridSize + 0.5) * GridSize 

    return Vector3.new(X, Y, Z)

end

mouse.Button1Down:Connect(function()
    Thing.CanCollide = true
    Thing.Transparency = 0
    Thing = SetUp()
end)

game:GetService("RunService").RenderStepped:Connect(function()
    Move()
end)


function Move()
    local target = mouse.Hit.p
    local face = mouse.TargetSurface
    mouse.TargetFilter = Thing
    local norm = Vector3.FromNormalId(face)
    Thing.Position = Round(target + (norm * 2), 4)
end

1 answer

Log in to vote
0
Answered by 2 years ago

Hmm, I'm not completely sure but I'd guess it's something to do with all of the rounding. How big does your baseplate have to be for it to work? And at what size does it stop working?

0
idk but it works at 4, 12, 20, 28 LOLLOLOLOLOLO12158 7 — 2y
0
Maybe a dumb question but why are there 4 numbers? - if you make the "4" smaller does it stop working? If yes then it's probably to do with rounding, just try to have your baseplate big enough or rethink your script :) AlexTheCreator 461 — 2y
Ad

Answer this question