I am making a prop placer, the issue is that I can’t figure out a way to make the rotation work when when it’s adjusting to the raycast normal when it’s on a wall.
local function onRenderStepped()
-- configure raycast params
raycastParameters.FilterDescendantsInstances = { selectedProp, player.Character }
-- shoot raycast
local mouseRay = camera:ScreenPointToRay(mouse.X, mouse.Y, 0)
local raycastResults = game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * RAYCAST_DISTANCE, raycastParameters)
local mousePos -- to be used
-- check if mouse is in-range, and if not move it to the closet spot possible
if not raycastResults then
mousePos = mouseRay.Origin + (mouseRay.Direction * RAYCAST_DISTANCE)
else
mousePos = raycastResults.Position
end
-- If the prop is not paused
if not pausedProp then
-- Offset prop's position to account for it sinking half way down
local propHeightOffset = selectedProp.PrimaryPart.Size.Y / 2 -- the part is halfway down, so it just needs to go halfway back up
-- it's just not visible because we're using a BASE instead of the whole prop itself.
if xOnlyRotation ~= nil then
propCFrame = CFrame.new(mousePos + Vector3.new(0, propHeightOffset, 0)) * xOnlyRotation.Rotation
if raycastResults then propCFrame = CFrame.lookAt(propCFrame.Position, propCFrame.Position + raycastResults.Normal) * CFrame.Angles(math.rad(-90), 0, 0) * xOnlyRotation.Rotation end
else
propCFrame = CFrame.new(mousePos + Vector3.new(0, propHeightOffset, 0))
if raycastResults then propCFrame = CFrame.lookAt(propCFrame.Position, propCFrame.Position + raycastResults.Normal) * CFrame.Angles(math.rad(-90), 0, 0) end
end
end
-- if rotation is activated
if rotatingProp then
local currentPos = selectedProp.PrimaryPart.Position
OnlyRotation = CFrame.new(currentPos, Vector3.new(mousePos.X-.00001, currentPos.Y, mousePos.Z-.00001))
local newPivot = CFrame.new(currentPos) * xOnlyRotation.Rotation -- Keeps position intact but applies rotation
--local newPivot = CFrame.lookAt(currentPos, Vector3.new(mousePos.X-.00001, currentPos.Y, mousePos.Z-.00001))
selectedProp:PivotTo(newPivot)
propCFrame = newPivot
end
-- finalize prop visual
if propCFrame then selectedProp:PivotTo(propCFrame) end
selectedProp.Parent = game.Workspace
end
This is what happens:
This is from another game, which is what I want: