CameraService
A New Camera for a New Roblox.
Just a heads-up that this is my first-ever open-source for any of my programming projects, so hopefully I’m doing this right.
For the past few months, I, along with my development team, have been working on an ambitious MMORPG project on the Roblox platform. A key theme we decided early on was to focus on immersion and realism, and as a result, I decided to create a custom camera system that serves that purpose. And as seen by this post, I’ve decided to open-source it, letting developers of all kinds be able to implement new, breathtaking camera views into their games and experiences in just a few lines of code!
See CameraService in Action & Games!
Using CameraService? Wanna be featured? Message me your game, and I’ll add you on here!
Neohex by the Neohex Team (indie team I’m apart of)
1st Place in the Roblox Inspire 2024 Challenge for Global Citizenship!
Subsist (Survival) by @Lechegaming83
A work-in-progress survival game!
The Features
The list of features goes on and on, some of which include:
- Different, customizable properties that developers can play around with and implement, including the camera’s smoothness, zoom, offset from the part it’s focusing on, and more.
- Seamlessly transitioning between different camera views (first-person, third-person, shift-lock, etc.), and letting you create your own!
- Smooth camera movements, rather than Roblox’s usual instantaneous movements
- The ability to tilt the camera with ease, opening the door to advanced-like camera manipulation to beginners.
- Properties that let you enable aesthetically appealing effects on the player’s character, such as having their body follow the mouse.
- Shaking camera effects that can be used for a multitude of purposes.
- Ability to lock camera panning on the X and Y axes.
- Compatible on laptop, mobile, and console.
Demonstrations
Here are videos showcasing some of CameraService’s features and built-in camera views:
You can see a tech demo of CameraService for yourself here.
Third Person
CameraService’s default third person camera view is in sharp contrast with Roblox’s traditional camera, providing additional features such as smooth movements, and character rotation based off mouse input.
First Person
This system provides built-in first person, already doing the work of restricting zoom. Like third person, there is more smoother movements. Additionally, a FirstPersonVariant
is also present as another camera view, which allows you to see your character’s own body while in first-person mode.
Shift Lock
CameraService supports a camera view that imitates shift lock’s offset. Using the API, you, the developer, are able to customize the smoothness, offset, and much more in addition.
Custom Views
CameraService enables you to create your own camera views, allowing for what would’ve been tedious hours of camera manipulation programming to be condensed into creating something like this in just a couple minutes!
Shaking and Tilting
These two are embedded as methods that can be called through CameraService.
Documentation
:SetCameraView(__type: string)
Sets the camera to a certain view, such as first person, shift-lock, or some other.
Will error if CameraService cannot find the camera view.
A camera view MUST be set in order to use the rest of the CameraService API.
:CreateNewCameraView(id: string, settingsArray: table)
Adds a new camera view that the camera can be set to.
settingsArray
should have values for camera view properties as seen below in :Change().
If no value is provided, a default one will be placed within.
:LockCameraPanning(xAxis: bool, yAxis: bool, lockAtX: number, lockAtY: number)
Locks camera movement from right-to-left (x-axis) or up-down (y-axis) 3rd and 4th parameters are optional. If the camera is locked, it’ll lock at the rotation of those parameters. Input should be in degrees for that.
:SetCameraHost(newHost: BasePart)
Has the camera focus in on the input part. Must be a BASEPART (not a model).
To reset the host back to the player’s character, you can leave the parameters blank.
:Change(property: string, val: any, changeDefaultProperty: boolean)
Properties include:
"CharacterVisibility" (string):
Determines what part of the character is visible.
when it’s the host. “All” shows all parts, “Body” hides the head, & “None” hides the whole body.
"MinZoom" (number)
: Determines how close the player can zoom in. In studs.
"MaxZoom" (number):
Determines how far the player can zoom out. In studs.
"Zoom" (number):
The current distance the camera is away from the host.
"Smoothness" (number):
Determines how smooth the camera movement is.
Intervals from 0-1 are suggested. Intervals higher could be used to create a “cinematic” effect.
"Offset" (CFrame):
Determines the offset/positioning away from the camera host.
Can be used to simulate shift-lock.
"LockMouse" (boolean):
Has the mouse locked in at the center.
"AlignChar" (boolean):
If set to true, the character will rotate itself based off the camera (highly advised for shift-locks and first person)
"BodyFollow" (boolean):
If AlignChar is NOT enabled, BodyFollow allows for an effect that has the upper body slightly rotate based off the mouse location.(only works for R15 rigs)
:ChangeSensitivity(val: number)
Changes the rate at which the camera moves.
Merely adjusts the UserInputServiceService.MouseDeltaSensitivity property.
NOTICE: Players CAN change this themselves manually through the Roblox menu.
:ChangeFOV(val: number, instant: boolean)
Gradually changes the field-of-view of the current camera.
If you want the change to be instantaneous, add a second parameter marked true.
Changing FOV directly with the actual camera object is still possible.
:Shake(intensity: number, duration: number)
Note: This function does yield for the duration of time inputted.
Creates a shaking camera effect in which the screen is, well, shaking. Like an earthquake.
Intensity should be a number greater than 0, preferably in the 0-1 range. Duration is in seconds.
:Tilt(degree: number)
Tilts the camera across the z-axis on whatever object it is currently focusing on.
Useful for creating camera effects. Input a number in degrees.
:Tilt(degree: number)
Tilts the camera across the z-axis on whatever object it is currently focusing on.
Useful for creating camera effects. Input a number in degrees.
:TiltAllAxes(x: number, y: number, z: number)
Like :Tilt, but allows you to adjust all 3 axes. Most likely use-case would be for creating camera effects. Inputs in X,Y,Z order
:SetWobbling(value: number)
Determines the amount of dynamic wobbling enabled. The larger the value, the less wobbling. To disable it, set the value to 0.
Examples
Say you wanted to recreate the cinematic camera effect seen at the very top and in demonstrations. To create something like that, your program would look like:
local CameraService = require(script.Parent.WhereverThisIsPlaced.ShouldBeOnTheClient)
local information = {
Smoothness = 10,
CharacterVisibility = "All",
MinZoom = 10,
MaxZoom = 10.001, --> To avoid running into math errors, make sure MaxZoom and MinZoom have a difference of at least 0.001.
Zoom = 10,
AlignChar = false,
Offset = CFrame.new(),
LockMouse = false,
BodyFollow = false
}
CameraService:CreateNewCameraView("Cinematic", information)
CameraService:SetCameraView("Cinematic") --> Tada!
CameraService:ChangeFOV(90, false) --> You could also add a bit more with changing the FOV.
And let’s say you wanted you wanted to just simply have players start in CameraService’s third-person when they join. It’s simply a matter of just a couple lines.
local CameraService = require(script.Parent.WhereverThisIsPlaced.ShouldBeOnTheClient)
CameraService:SetCameraView("ThirdPerson")
--> Other built-in camera views include: FirstPerson, FirstPersonVariant, and ShiftLock
--> And if we wanted to spice it up, and have it feel like an explosion?
--> When the character steps on a certain part, it can go like this:
local player = game.Players.LocalPlayer
local debounce = false
workspace.ExplosionPart.Touched:Connect(function(hit)
if not debounce and hit and player and player.Character and hit.Parent == player.Character then
debounce = true
CameraService:Shake(1, 5) --> Shakes heavily for 5 seconds.
end
end)
DISCLAIMERS:
- (DECEMBER 2024): As a result of recent Roblox updates and inherent floating point errors, CameraService is not optimal for 3rd-person views with R6 avatars. A potential patch is in the works.
- Due to UserInputService not recognizing the classic (not dynamic) Roblox thumbstick on mobile devices as a
GameProcessedEvent
, there may be some unusual behavior when using CameraService on mobile IF using the old thumbstick (the current dynamic thumbstick has no issues).
Where to Obtain CameraService
- Technical Document (If you wanna read up on the specifics!)
- GitHub
-
Roblox Asset Library
An API reference webpage is planned! Stay tuned.
Latest Update (v2.0):
You can also contact me on Discord at @lugical.me and on Twitter.
I’m always looking to help showcase & support any games using CameraService. If you are, feel free to let me know, so I can shout you out in the post!