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
5 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

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

Answer this question