Hello, I’m making a placing system and I got a problem, I don’t know how to clamp my model to the plot bounds, I know the common method that uses math.clamp
but my models have multiple primary parts, I use each part to represent a face of the model because I’m trying to make a snap placing system and this is the best I got
This is one of my models to give a better idea of what I’m saying with “faces”
I used attachments as a reference. Basically, I want to clamp that object to the bounds, I’ll explain my problem with the video below this text
I’m using the method explained here
and this is my code
local function getPosition(center, gridSize, getFace)
local pos, normal = mouse.Hit, mouse.TargetSurface
--pos = playerPlot:LimitPosition(pos, realSize)
local pos2 = snapGrid(gridSize, normal, pos+(center.Size * normal)/2)
local CF = CFrame.lookAt(pos2,pos2+normal) --+ (center.Size * normal)/2
local backup = CF
if getFace then
local s, e = pcall(function()
if getIndexNum(faces, normal) > 4 then
if normal == Vector3.new(0, -1, 0) then
facesFolder = "TopFaces"
model.PrimaryPart = model[facesFolder][rotationSteps[rotationStep]]
else
facesFolder = "Faces"
model.PrimaryPart = model[facesFolder][rotationSteps[rotationStep]]
end
CF = CFrame.new(pos) + (Vector3.new(0, model.PrimaryPart.Size.Y/2, 0) * normal.Y)
CF = CF * CFrame.Angles(0, math.rad(mouse.Target.Orientation.Y), 0)
return CF,normal
else
--facesFolder = "MiddleFaces"
--model.PrimaryPart = model[facesFolder][rotationSteps[rotationStep]]
end
end)
if not s then
CF = backup
end
end
oldCF = CF
return CF, normal
end