hi. im trying to make a custom camera script to go along with some other custom stuff im making. ive got the concept down at a basic level but the camera can roll around all willy nilly as seen here:
https://gyazo.com/c1f1bcdbd7434660a71634d0049c507a
obviously, this isnt desired behavior. if you face forward it works correctly but if you start to turn backwards the Y axis randomly inverts. im pretty sure this is an issue with how im treating my values, but im unsure of the mathematical processing i need to do with them in order to get the camera to behave correctly. the default camera scripts are a bit of a miss in terms of readability, so no luck there.
code
function CameraController:Start()
local plr = self.Player
self.Cam = workspace.CurrentCamera
self.Enabled = true
self.SensitivityX = 0.2
self.SensitivityY = 0.2
self.CamOffset = Vector3.new(0,3,0)
self.Pitch = 0 --how far we've traveled in total on the Y axis
self.Yaw = 0 --ditto, X axis
self.RotateInput = ZERO_VECTOR2 --where we want to go this frame
runService.RenderStepped:Connect(function()
self:Update()
if not self.Cam then
return
end
local chr = plr.Character
local camCF = self.Cam.CFrame
if chr and chr.PrimaryPart then
local root = chr.PrimaryPart
self.Cam.CFrame = CFrame.new(root.Position + self.CamOffset) * CFrame.Angles(math.rad(self.Pitch),math.rad(self.Yaw),math.rad(0))
--self.Yaw = 0
print(self.Yaw)
end
end)
userInputService.InputChanged:Connect(function(input,processed)
if not processed then
if input.UserInputType == Enum.UserInputType.MouseMovement then
if self.Enabled and self.Cam then
local delta = input.Delta
local deltaX = delta.X * self.SensitivityX
local deltaY = delta.Y * self.SensitivityY
self.Pitch += -deltaY
self.Yaw += -deltaX
self.RotateInput += Vector2.new(-deltaX,-deltaY)
--self.Cam.CFrame *= CFrame.Angles(math.rad(-deltaY),math.rad(-deltaX),math.rad(0))
end
end
end
end)
end
any help is appreciated!