Trying to achieve this kind of part panning behavior on surfaces using raycasters
(red squares show how it should be right)
In essence, it’s doing alright when raycasted perpendicular to the surface, but otherwise it rotates wrong.
Need some help gathering the offset angle
Code snippet:
local cam = workspace.CurrentCamera
local mouse = player:GetMouse()
local angle = 0
runSv.RenderStepped:Connect(function(dt)
local mousePos = mouse.Hit.p
local camPos = cam.CFrame.p
local diff = (mousePos-camPos)
local mag = diff.magnitude
local result = workspace:Raycast(camPos,diff.Unit*500,filter)
if result == nil then
if prevPart.Parent ~= script then
prevPart.Parent = script
end
else
if prevPart.Parent ~= workspace then
prevPart.Parent = workspace
end
local norm = result.Normal
local lookV = cam.CFrame.lookVector
local fw = norm:Cross(lookV):Cross(norm)
prevPart.CFrame = CFrame.lookAt(result.Position, result.Position+fw, -norm) *
CFrame.Angles(0,math.rad(angle)+90-vectorsAngle(fw,lookV),0) -- what should I do here in order to make the movement right ?
end
end)