Any ways to optimize this CameraModule of mine?

Include a standalone, bare-bones rbxl file with only the code you want reviewed.

cameraModule.rbxl (21.4 KB) (in replicated storage)

  • What does the code do and what are you not satisfied with?

The code acts as a replacement for the default camera module(s) that roblox provides each game with. It works fully on PC and mobile, I think it’s pretty well optimized but I get the feeling there’s more I could optimize here

What potential improvements have you considered?

Quite a lot, to show a few:

-- old
cameraAngle = CFrame.Angles(0, xAngle, 0) * CFrame.Angles(yAngle, 0, 0)
--new
cameraAngle = CFrame.fromOrientation(yAngle, xAngle, 0)
--old
camera.CFrame = cameraAngle + primaryPart.Position * offset
-- new
camera.CFrame = cameraAngle + primaryPart.Position -- offset is included into cameraAngle
inputService.MouseBehavior = Enum.MouseBehavior.LockCenter
-- ^ done on input instead of render stepped
-- old
local delta = input.Delta

xAngle = xAngle - (delta.X * 0.004)
yAngle = yAngle - (delta.Y  * 0.004)

-- new
local delta = -input.Delta * 0.004
	
xAngle += delta.X
yAngle += delta.Y
  • How (specifically) do you want to improve the code?

I’d like some ways to better optimize a few parts, I’m completely satisfied with the render stepped part, I’d be very suprised if that could be further optimized at all.

The input part just seems like it could potentially have some way to make it better but I can’t think of what…

Also random thing worth noting, in my actual game with this module I use an input handler and a render stepped caller to avoid multiple connections, unecessary coroutines, etc. Just incase anyone suggests to use those

Thanks for any help :stuck_out_tongue:

1 Like