I tried checking if the rotatevalue is 180 but it does not work either
Script:
local nearestSnap = .5
function roundToNearest(x,num,normal)
if num == 'x' then
if normal.X ~= 0 then
return x else
return nearestSnap * math.floor(x / nearestSnap)
end
elseif num == 'y' then
if normal.Y ~= 0 then
return x else
return nearestSnap * math.floor(x / nearestSnap)
end
elseif num == 'z' then
if normal.Z ~= 0 then
return x else
return nearestSnap * math.floor(x / nearestSnap)
end
end
end
function Placement:CalcPlacementCFrame(model, positionX,positionY, rotation,turn)
local unitRay = workspace.CurrentCamera:ScreenPointToRay(positionX, positionY, 1) --origin, Vector3.new(0, -1, 0));
local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000)
local hit, pos, normal = game:GetService("Workspace"):FindPartOnRay(ray, model)
local tsize = model.PrimaryPart.Size
local
surfacePosition = (tsize*normal/2)
local finalpos = CFrame.new(pos+surfacePosition)
local snappedPosition = CFrame.new(
roundToNearest(finalpos.X,'x',normal),
roundToNearest(finalpos.Y,'y',normal),
roundToNearest(finalpos.Z,'z',normal)
)
return snappedPosition* CFrame.Angles(turn, rotation,turn)
end
I could be wrong, but I think when you are rotating it and placing it somewhere else, it’s not updating the hitbox, I could be wrong, but a wild guess.
oh yeah i guess you’re right it wasn’t updating the hitbox
so how do i make it so that it’s always like this:
and not this:
(the mouse is pointing on the left surface of the green part)
You can try this out, it’s my old version of the placement system. local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Placement = {}
local Base = {
Type = “BasePart”,
Name = “Base”
}
local Debug = true
local New = {
Type = “Model”,
Name = “New”,
Parent = workspace,
Archivable = true
}
local XZRay = Ray.new(Vector3.new(),Vector3.new())
local XYRay = Ray.new(Vector3.new(),Vector3.new())
local YZRay = Ray.new(Vector3.new(),Vector3.new())
local XZPos = nil
local XYPos = nil
local YZPos = nil
local function Clamp(V,Low,High)
return math.max(Low,math.min(High,V))
end
local function GetPosition(Ray,Model)
local X,Y,Z = Mouse.Hit.x,Mouse.Hit.y,Mouse.Hit.z
if Ray.Direction.x ~= 0 then
X = Model.PrimaryPart.Position.x
end
if Ray.Direction.y ~= 0 then
Y = Model.PrimaryPart.Position.y
end
if Ray.Direction.z ~= 0 then
Z = Model.PrimaryPart.Position.z
end
return Vector3.new(X,Y,Z)
end