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

Grid placement system, snapping to a 1x1x1 grid?

Asked by
I_Nev 200 Moderation Voter
4 years ago

I have a placement system and it always aligns great for the first placement, but after that it dis-aligns itself and i have tried so much to fix it, i don't want a super complicated script for this as i want to expand upon it myself, but any help is appreciated. Everything else works fine like rotating and placement and all that stuff, so i'll only include the snapping part, Maybe i missed something? I have no idea. A walk through would be greatly appreciated as i am trying to learn about this more

function Update()
    if model and BUILD_MODE_ACTIVE then
        SnapX = math.floor(Mouse.Hit.X/GridSize+0.5)
        SnapY = math.ceil(MyBase.Size.Y + model.Hitbox.Size.Y/2)
        SnapZ = math.floor(Mouse.Hit.Z/GridSize+0.5)
        model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame:Lerp(CFrame.new(SnapX, SnapY, SnapZ)*CFrame.Angles(0, math.rad(Rotation), 0), .25))
        CheckCollisions()
    elseif BUILD_MODE_ACTIVE == false then
        Box()
    end
end

Answer this question