so i was working with this camera panning script, which pans the camera based on where your mouse is on the screen, and i found that when i change the savedCF variable placement, the script function changes.
1st script, functions correctly but doesnt save the y angle of the pan
local RunService = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = game.Workspace.CurrentCamera
cam.CameraType = "Scriptable"
local camCF = workspace.gamer.CFrame
local angle = 0
RunService.RenderStepped:Connect(function()
local center = Vector2.new(cam.ViewportSize.X / 2, cam.ViewportSize.Y / 2)
local rotVector = Vector3.new(((mouse.X - center.X) / 150), (mouse.Y - center.Y) / 150, 0)
local savedCF = camCF
if mouse.X < 250 and angle > -180 then
print("panning left")
angle = angle - 1.5
cam.CFrame = savedCF * CFrame.Angles(0, math.tanh(-math.rad(cam.CFrame.Y + angle)), 0)
savedCF = cam.CFrame
wait(0.1)
elseif mouse.X > 1750 and angle < 180 then
print("panning right")
angle = angle + 1.5
cam.CFrame = savedCF * CFrame.Angles(0, math.tanh(math.rad(cam.CFrame.Y - angle)), 0)
savedCF = cam.CFrame
wait(0.1)
else
cam.CFrame = savedCF * CFrame.Angles(math.atan(math.rad(-rotVector.Y)), math.atan(math.rad(-rotVector.X)), rotVector.Z)
end
end)
https://gyazo.com/f7ff671ed5d235a1aca1d0fd7fb6aeb1
2nd script, saves the y angle but the panning works incorrectly
local RunService = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = game.Workspace.CurrentCamera
cam.CameraType = "Scriptable"
local camCF = workspace.gamer.CFrame
local angle = 0
local savedCF = camCF
RunService.RenderStepped:Connect(function()
local center = Vector2.new(cam.ViewportSize.X / 2, cam.ViewportSize.Y / 2)
local rotVector = Vector3.new(((mouse.X - center.X) / 150), (mouse.Y - center.Y) / 150, 0)
if mouse.X < 250 and angle > -180 then
print("panning left")
angle = angle - 1.5
cam.CFrame = savedCF * CFrame.Angles(0, math.tanh(-math.rad(cam.CFrame.Y + angle)), 0)
savedCF = cam.CFrame
wait(0.1)
elseif mouse.X > 1750 and angle < 180 then
print("panning right")
angle = angle + 1.5
cam.CFrame = savedCF * CFrame.Angles(0, math.tanh(math.rad(cam.CFrame.Y - angle)), 0)
savedCF = cam.CFrame
wait(0.1)
else
cam.CFrame = savedCF * CFrame.Angles(math.atan(math.rad(-rotVector.Y)), math.atan(math.rad(-rotVector.X)), rotVector.Z)
end
end)
https://gyazo.com/82b06d01420816c8cf0b59ba86551aab
how can i fix this??