I’m writing a smooth first person camera system like DOORS for my game, and wanted to use Quenty’s spring module instead of lerps to make my camera extra smooth. (the way the camera will slightly overshoot the mouse but correct itself smoothly). I got it to work perfectly with the camera position but the camera direction keeps glitching. I think it’s because the spring always tries to take the shortest route possible to the target direction, which is sometimes the opposite direction the mouse was actually moving. Here’s the code:
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Enabled = script:WaitForChild("CamEnabled")
local Camera = workspace.CurrentCamera
local ZERO_VECTOR = Vector3.new()
local SpringModule = require(script:WaitForChild("Spring"))
local CamPosSpring = SpringModule.new(ZERO_VECTOR)
CamPosSpring.Speed = 40
CamPosSpring.Damper = .3
local CamDirSpring = SpringModule.new(ZERO_VECTOR)
CamDirSpring.Speed = 30
CamDirSpring.Damper = .8
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid"):: Humanoid
local RootPart = Character:WaitForChild("HumanoidRootPart"):: Part
local function UpdateCameraMisc(enabled)
UIS.MouseIconEnabled = not enabled
if enabled == false then
Camera.CameraType = Enum.CameraType.Custom
if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter then
UIS.MouseBehavior = Enum.MouseBehavior.Default
end
else
Camera.CameraType = Enum.CameraType.Scriptable
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end
end
local UpdatedTransparency = false
local function SetBodyTransparency(transparency)
if not Character or UpdatedTransparency then
return
end
UpdatedTransparency = true
for _, v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") then
v.LocalTransparencyModifier = transparency
end
end
end
local CameraDirection = Vector2.new()
local Sensitivity = 0.3
local MaxLookRange = 85
local TargetCamPos, TargetCamDir = Camera.CFrame.Position, Vector3.new(Camera.CFrame:ToOrientation())
local function UpdateTargetValues()
CameraDirection -= UIS:GetMouseDelta() * Sensitivity
CameraDirection = Vector2.new(CameraDirection.X%360, math.clamp(CameraDirection.Y, -MaxLookRange, MaxLookRange))
TargetCamPos = RootPart.Position + Vector3.new(0, 1.5, 0)
TargetCamDir = Vector3.new(math.rad(CameraDirection.Y), math.rad(CameraDirection.X), 0)
end
RunService.RenderStepped:Connect(function()
SetBodyTransparency(Enabled.Value and 1 or 0)
UpdateCameraMisc()
UpdateTargetValues()
Camera.CFrame = CFrame.new(CamPosSpring.Position) * CFrame.fromOrientation(CamDirSpring.Position.X, CamDirSpring.Position.Y, 0)
CamPosSpring.Target = TargetCamPos
CamDirSpring.Target = TargetCamDir
end)
If anyone could help, I would greatly appreciate it.