Hello,
I am having an issue with my placement system, when I try to put models on the grid, sometimes they aren’t alligned. I looked around for issues like this but couldn’t find a solution. Heres a video showing the issue:
Video
The first model isn’t alligned to the grid while the second one works just fine.
Code
local cframe, size = model:GetBoundingBox()
local xsize = size.X
local is_even = xsize % 2 == 0
local zsize = size.Z
local is_even2 = zsize % 2 == 0
local g = 1
local function moveditem()
local x = math.sign(mouse.Hit.Position.X)*((math.abs(mouse.Hit.Position.X) - math.abs(mouse.Hit.Position.X) % g) + (size.X % g))
local z = math.sign(mouse.Hit.Position.Z)*((math.abs(mouse.Hit.Position.Z) - math.abs(mouse.Hit.Position.Z) % g) + (size.Z % g))
local newlocation = Vector3.new(x, model.WorldPivot.Y, z)
if is_even == true then
if rotation == 90 or rotation == -90 then
newlocation = Vector3.new(newlocation.X, newlocation.Y, newlocation.Z + 0.5)
else
newlocation = Vector3.new(newlocation.X + 0.5, newlocation.Y, newlocation.Z)
end
end
if is_even2 == true then
if rotation == 90 or rotation == -90 then
newlocation = Vector3.new(newlocation.X - 0.5, newlocation.Y, newlocation.Z)
else
newlocation = Vector3.new(newlocation.X, newlocation.Y, newlocation.Z - 0.5)
end
end
local newrotation = CFrame.Angles(0, math.rad(rotation), 0)
local cframe = CFrame.new(newlocation) * newrotation
model:SetPrimaryPartCFrame(cframe)
Any help is appreciated!