I have a custom camera system that I made myself but, I need help rotating the character to the camera like AutoRotate
Here is the script (In StarterCharacterScripts)
local Player = game:GetService("Players").LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local HRP = Char:WaitForChild("HumanoidRootPart")
local Humanoid = Char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local Settings = UserSettings():GetService("UserGameSettings")
local RunService = game:GetService("RunService")
local Camera = workspace:WaitForChild("Camera")
local AngleX, AngleY = 0, 0
local Rad = math.rad
local NewCF = CFrame.new
local CamAngleCurrent = NewCF()
local BobbleAngleCurrent = NewCF()
local TiltAngleCurrent = NewCF()
local CameraMoving = true
local BobbleIntensity = 1
local SensModifier = 0.3
local MinYAngle = 85
local MaxYAngle = -MinYAngle
Camera.CameraType = Enum.CameraType.Scriptable
Camera:GetPropertyChangedSignal("CFrame"):Connect(function()
for _,v in pairs(Char:GetDescendants()) do
if (v:IsA("BasePart") or v:IsA("Decal") or v:IsA("Texture")) and not v:FindFirstAncestorOfClass("Tool") then
v.LocalTransparencyModifier = 1
end
end
end)
local function Tilt(Delta)
local Dot = -Camera.CFrame.RightVector:Dot(Humanoid.MoveDirection) * 0.08
local Moving = (HRP.AssemblyLinearVelocity.Magnitude - Humanoid.WalkSpeed + 6) > 0
local Time = tick() * Humanoid.WalkSpeed
local BobbleAngleX = math.sin(Time) * 0.012 * BobbleIntensity
local BobbleAngleZ = math.sin(Time * 1.2) * 0.015 * BobbleIntensity
if not Moving then Dot = 0 BobbleAngleX = 0 BobbleAngleZ = 0 end
local CamTilt = CFrame.Angles(0, 0, Dot * BobbleIntensity)
local BobbleAngle = CFrame.Angles(BobbleAngleX, 0, BobbleAngleZ)
BobbleAngleCurrent = BobbleAngleCurrent:Lerp(BobbleAngle, 10 * Delta)
TiltAngleCurrent = TiltAngleCurrent:Lerp(CamTilt, 6 * Delta)
end
local function MoveCam(Delta)
Tilt(Delta)
local MouseDelta = UIS:GetMouseDelta()
local Sensitivity = Settings.MouseSensitivity
local _, TurningAngle, _ = Camera.CFrame:ToOrientation()
AngleX += Rad((MouseDelta.X * SensModifier) * Sensitivity * -1)
AngleY += Rad((MouseDelta.Y * SensModifier) * Sensitivity * -1)
AngleY = math.clamp(AngleY, Rad(MaxYAngle), Rad(MinYAngle))
CamAngleCurrent = CamAngleCurrent:Lerp(CFrame.fromEulerAnglesYXZ(AngleY, AngleX, 0), 50 * Delta)
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
HRP.CFrame = HRP.CFrame * CFrame.fromOrientation(0, TurningAngle, 0)
Camera.Focus = CFrame.new(Char.PrimaryPart.Position)
Camera.CFrame = Camera.Focus
Camera.CFrame *= CamAngleCurrent * BobbleAngleCurrent * TiltAngleCurrent
end
RunService:BindToRenderStep("CameraControls", 0, function(Delta)
if CameraMoving then
MoveCam(Delta)
end
end)
Humanoid.Died:Connect(function()
RunService:UnbindFromRenderStep("CameraControls")
UIS.MouseBehavior = Enum.MouseBehavior.Default
end)