My placement function isn’t behaving as intended and I’m not well-versed with maths:
- Is slightly hovering
- It’s like it’s shifting completely. From the start of XZ Corner, it doesn’t go right to the edge, it just stops at the last increment for X-axis and for Z-axis it stops at 3 studs away to the end, on the opposite corner it goes out of the grid by several studs.
local MRay = Mouse.UnitRay
local RayResult = workspace:Raycast(MRay.Origin, MRay.Direction.unit * MaxPlaceDistance, RetrieveParams(Model))
if RayResult then
--
LOWER_X_BOUND = Plot.Position.X - (Plot.Size.X*0.5)
UPPER_X_BOUND = Plot.Position.X + (Plot.Size.X*0.5) - Model.PrimaryPart.Size.Z
LOWER_Z_BOUND = Plot.Position.Z - (Plot.Size.Z*0.5)
UPPER_Z_BOUND = Plot.Position.Z + (Plot.Size.Z*0.5) - Model.PrimaryPart.Size.X
--
local EndPos = RayResult.Position + (RayResult.Normal * (Model.PrimaryPart.Size*.5))
--
local posX = clamp(tonumber(EndPos.X), LOWER_X_BOUND, UPPER_X_BOUND)
local posZ = clamp(tonumber(EndPos.Z), LOWER_Z_BOUND, UPPER_Z_BOUND)
--
Model:SetPrimaryPartCFrame(CFrame.new(SnapTo(posX),SnapTo(tonumber(EndPos.Y)),SnapTo(posZ)))
end
Could someone point out where I’m going wrong with this? (It’s sandbox-type grid placement)
– FOOTAGE/IMAGE OF ALL LISTED ISSUES
https://medal.tv/games/roblox/clips/7PcKv_T4KlLht/d13378pAn5Is?invite=cr-MSxCemQsMTQ1MTM3ODAs
https://medal.tv/games/roblox/clips/7PcS1tbsnSC8H/d1337SbOgJI0?invite=cr-MSxpNEssMTQ1MTM3ODAs