Trying to make objects position themself right up to a wall even when rotated. Currently only works when not rotated
The first thing I tried:
-- item size is model:GetExtentsSize()
connections.runConnect = runs.RenderStepped:Connect(function()
local ray = rayFunction(params) -- raycasts from player mouse if computer, and camera if mobile
if ray == nil then return end
local toGrid = module.Snap(ray) -- returns a rounded ray.Position
local cf = CFrame.new(toGrid + (ray.Normal * itemSize / 2)) * module.Pivot -- the rotation of the obj in CFrame.Angles
selectedItem:PivotTo(cf)
end)
This is what it looks like normally:
This is what it looks like when rotated
PS: Objects can also be placed on floors
This is the best I’ve got so far, it adjusts based on rotation but not the correct distance:
local function RotateVector(vector, rotationCFrame)
return rotationCFrame:PointToWorldSpace(vector)
end
connections.runConnect = runs.RenderStepped:Connect(function()
local ray = rayFunction(params)
if ray == nil then return end
local toGrid = module.Snap(ray)
local rotationCFrame = selectedItem:GetPivot()
local rotatedSize = RotateVector(itemSize, rotationCFrame)
local adjustedPosition = toGrid + ray.Normal * (rotatedSize.magnitude / 2)
adjustedPosition = adjustedPosition - Vector3.new(0, rotatedSize.y / 2, 0)
selectedItem:PivotTo(CFrame.new(adjustedPosition) * module.Pivot)
end)
Looking for anyones help if you’ve got ideas. Cheers