Quick little camera script for 2D/RPG style games I made with TweenService.
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hmr = char:WaitForChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
local function updateCamera()
local targetCFrame = CFrame.new(hmr.Position + Vector3.new(0, 20, 0), hmr.Position)
TweenService:Create(Camera, TweenInfo.new(0.35, Enum.EasingStyle.Sine), {CFrame = targetCFrame}):Play()
end
RunService:BindToRenderStep("CharacterRotate", Enum.RenderPriority.Camera.Value + 1, function()
local mouse = plr:GetMouse()
local mousePos = Vector3.new(mouse.Hit.p.X, hmr.Position.Y, mouse.Hit.p.Z)
hmr.CFrame = CFrame.new(hmr.Position, mousePos)
updateCamera()
end)
char.Humanoid.Died:Connect(function()
RunService:UnbindFromRenderStep("CharacterRotate")
end)
plr.CharacterAdded:Connect(function()
script.Disabled = true
task.wait()
script.Disabled = false
end)