Hi!
I’ve made a custom camera movement for my new game that works good, until I wanna turn the camera. When that happens the movement is inverted and not smooth.
I will provide footage of it working properly and it not working properly.
WORKING FOOTAGE
https://gyazo.com/bc76c8ad92189cb25197d60515d40c21
WORKING SCRIPT
Mouse.Move:Connect(function(input)
local MousePosition = Mouse.Hit.Position
local cameraCFrame = CFrame.lookAt(ReplicatedStorage:WaitForChild("DefaultPosition").Position, MousePosition)
local X, Y, Z = cameraCFrame:ToEulerAnglesXYZ()
local maxRotation = math.rad(20)
local newRotation = Vector3.new(
math.clamp(X, -maxRotation, maxRotation),
math.clamp(Y, -maxRotation, maxRotation),
0
)
newRotation = CFrame.fromEulerAnglesXYZ(newRotation.X, newRotation.Y, newRotation.Z)
local finalCFrame = newRotation + ReplicatedStorage:WaitForChild("DefaultPosition").Position
local Tween = TweenService:Create(self.Camera, TweenInfo.new(0.4), {CFrame = finalCFrame})
Tween:Play()
end)
WHEN I TRY TO TURN IT
https://gyazo.com/e64817c0d5382ffc0e63ba276f552367
THE NOT WORKING SCRIPT
Mouse.Move:Connect(function(input)
local MousePosition = Mouse.Hit.Position
local cameraCFrame = CFrame.lookAt(ReplicatedStorage:WaitForChild("DefaultPosition").Position, MousePosition)
local X, Y, Z = cameraCFrame:ToEulerAnglesXYZ()
local maxRotation = math.rad(20)
local newRotation = Vector3.new(
math.clamp(X, -maxRotation, maxRotation),
math.clamp(Y, -maxRotation, maxRotation),
0
)
newRotation = CFrame.fromEulerAnglesXYZ(newRotation.X, newRotation.Y, newRotation.Z)
local finalCFrame = (newRotation + ReplicatedStorage:WaitForChild("DefaultPosition").Position) * CFrame.Angles(0, math.rad(180), 0)
local Tween = TweenService:Create(self.Camera, TweenInfo.new(0.4), {CFrame = finalCFrame})
Tween:Play()
end)
I basically want to turn the camera without the movement breaking.
Thanks for any help!