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

Why does my placement system break when I snap to the grid?

Asked by 3 years ago

My placement system works fine when the parts are axis-aligned, but when they are not the snapping completely breaks.

Axis Aligned

Non Axis Aligned (You can see that the collision is also weird)

Here is the code im using to calculate the position

-- RayInst is just Mouse.Target but using a ray

function SnapAxis(num)
    local Grid = ValueFolder:GetAttribute("MoveGridSize")

    return math.floor(num / Grid + 0.5) * Grid
end

local pos = Vector2.new(SnapAxis(RayPos.X), SnapAxis(RayPos.Z))

local CF = CFrame.Angles(Orientation.X, Orientation.Y, Orientation.Z) + Vector3.new(pos.x,
RayInst.Position.Y+(RayInst.Size.Y/2)+(Preview.PrimaryPart.Size.Y/2), pos.Y)

Preview:SetPrimaryPartCFrame(CF)

I know the problem is the way I snap to the grid because it works fine when I dont snap.

My goal is to make a placement system similar to the one in the game Build a Boat for Treasure.

I tried multiple stuff and its not working, thanks in advance!

Answer this question