I’m making (or at least trying to make) a performant game that takes as few user resources as possible while trying not to look like a 2008 game. I wrote a custom camera script already and I want to know if it’s possible to optimize it
Here it is:
local Camera = workspace.CurrentCamera
local CameraPart = script:WaitForChild("CameraPart")
local Character = script.Parent.Parent.Parent
local Humanoid:Humanoid = Character.Humanoid
local HumanoidRootPart:Part = Character.HumanoidRootPart
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local UserGameSettings:UserGameSettings = UserSettings():GetService("UserGameSettings")
local RotX,RotY = 0,0
local LockCenterEnum = Enum.MouseBehavior.LockCenter
local Plus1Point5Vector = Vector3.new(0,1.5,0)
local Clamp = math.clamp
local Rad = math.rad
local CFrameNew = CFrame.new
local CFrameYXZ = CFrame.fromEulerAnglesYXZ
local RenderEvent = function(DT)
local DeltaMove = UserInputService:GetMouseDelta()
RotX,RotY = RotX-DeltaMove.Y*UserGameSettings.MouseSensitivity,RotY-DeltaMove.X*UserGameSettings.MouseSensitivity
RotX = Clamp(RotX,-85,85)
CameraPart.CFrame = CFrameNew(HumanoidRootPart.Position+Humanoid.CameraOffset+Plus1Point5Vector)*CFrameYXZ(Rad(RotX),Rad(RotY),0)
Camera.CFrame = script.Camera.CFrame
end
Camera.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseBehavior = LockCenterEnum
local Event = RunService.RenderStepped:Connect(RenderEvent)
UserInputService.WindowFocused:Connect(function()
UserInputService.MouseBehavior = LockCenterEnum
end)
for i,v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") then
v.LocalTransparencyModifier = 1
end
if v:IsA("Accessory") then
v.Handle.LocalTransparencyModifier = 1
end
end