CameraService - A New Camera for a New Roblox

Simply put, it works well, and I’m happily using it in my game. Highly recommended for anyone looking to enhance their game’s camera experience.

1 Like

We’re still looking to show some love! If you’re using CameraService in any current or past projects of yours, let me know, and I can link it in the OP!

2 Likes

Is there a suitable method to implement a feature similar to what “REALISM” provides? Where players can virtually aim weapons in the direction the character is looking?

Hello ive noticed one error, when switching to Default, the character doesnt rotate towards the camera. I tried turning on AutoRotate but to no effect. How can I fix this?
https://gyazo.com/9b56a356a51b804c4daf6ccebd91269c

I thought I got this version, But I noticed when holding tools and moving backwards, my characters jitter quite a lot.

Could you send a video and the file that you’re using?

1 Like

Does this allow for camera spots such as a cutscene? Also for the 1st person camera could we customize it, such as changing the amount of body visible by looking down?

I was unsure if you meant here or your messages, I logically chose the latter, lol. But I sent it :wink:

Yes!
Technically, you could do cutscenes in CameraService by creating a camera view, setting the host to a part, and then tweening that part. However, I personally would recommend disabling CameraService and simply interpolating/tweening yourself.

And for the 1st person camera, yes! There’s a statement on Lines 267 and 444 (if I remember correctly), where you can alter the angles from 60 degrees to something else. If more people have a use to alter it, I’d be happy to make altering that a bit easier in a future release!

v2.1.0 is out!

Patches to the backwards jittery motion, Default motion issues, output error spam, as well as a new method to change vertical range of motion (:SetVerticalRange(angle: number)) are out now on both GitHub and Roblox Marketplace!

1 Like

Sweet! would this VerticleRange have a use-case for something like recoil effect for the camera?

To be honest, I don’t see recoil being a heavy use-case for this (probably more use of :Shake or the Offset property), but definitely great if you need to restrict the range of motion for something, like looking through a telescope.

I thought i should post here since my attempted soulution involves the LockCameraPanning method. The video explains the problem better than I can.
robloxapp-20240409-1318299.wmv (3.3 MB)

local c = script.Parent

local holdingKey = false

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

-- Ensure that the character's humanoid contains an "Animator" object
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")


local uis = game:GetService("UserInputService")

local leftAnimation = Instance.new("Animation")
leftAnimation.AnimationId = "rbxassetid://17014677879"

-- Wallrun Camera


local CameraService = require(game.ReplicatedStorage.Dependencies.CameraService)
local information = {
	Smoothness = .6,
	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 = true,
	Offset = CFrame.new(2,0,0),
	LockMouse = true,
	BodyFollow = false
}

local information2 = {
	Smoothness = .6,
	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("WallrunCamera", information)
CameraService:CreateNewCameraView("Aim", information)
CameraService:CreateNewCameraView("Unlock", information2)

-- Load the animation onto the animator
local leftAnim = animator:LoadAnimation(leftAnimation)

local rightAnimation = Instance.new("Animation")
rightAnimation.AnimationId = "rbxassetid://17014672160"


-- Load the animation onto the animator
local rightAnim = animator:LoadAnimation(rightAnimation)
rightAnim.Priority= Enum.AnimationPriority.Action2


uis.InputBegan:Connect(function(inp, p)

	if not p and inp.KeyCode == Enum.KeyCode.LeftShift then
		holdingKey = true
	end
end)

uis.InputEnded:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.LeftShift then
		CameraService:LockCameraPanning(false, false)
		holdingKey = false
	end
end)
	

game:GetService("RunService").Heartbeat:Connect(function()
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude; raycastParams.FilterDescendantsInstances = {c}; raycastParams.IgnoreWater = true
	
	local rayL = workspace:Raycast(c.HumanoidRootPart.CFrame.Position, -c.HumanoidRootPart.CFrame.RightVector * 2.7, raycastParams)
	local rayR = workspace:Raycast(c.HumanoidRootPart.CFrame.Position, c.HumanoidRootPart.CFrame.RightVector * 2.7, raycastParams)
	
	local ray = rayL or rayR
	
	if ray and holdingKey then
		
		if ray == rayL then
			if not leftAnim.IsPlaying then 
				
				leftAnim:Play()
				c.statusHandler.status.Value = "Wallrunning"
				CameraService:SetCameraView("WallrunCamera")
				CameraService:LockCameraPanning(true, true, 90)
			end
			rightAnim:Stop()
		else
			if not rightAnim.IsPlaying then
				rightAnim:Play() 
				c.statusHandler.status.Value = "Wallrunning"
				CameraService:SetCameraView("WallrunCamera")
				CameraService:LockCameraPanning(true, true, 270)
			end
			leftAnim:Stop()
		end
		
		local part = ray.Instance
		
		local weld = c.HumanoidRootPart:FindFirstChild("WallrunWeld") or Instance.new("WeldConstraint")
		weld.Name = "WallrunWeld"
			
		weld.Part0 = c.HumanoidRootPart
		weld.Part1 = part

		local bp = c.HumanoidRootPart:FindFirstChild("WallrunBodyPosition") or Instance.new("BodyPosition", c.HumanoidRootPart)
		bp.Name = "WallrunBodyPosition"
		bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		bp.Position = c.HumanoidRootPart.Position + workspace.CurrentCamera.CFrame.LookVector * 10
			
	else
			
		for i, child in pairs(c.HumanoidRootPart:GetChildren()) do

			if child.Name == "WallrunWeld" or child.Name == "WallrunBodyPosition" then

				child:Destroy()
			end
		end
		c.statusHandler.status.Value = "nil"
		leftAnim:Stop()
		rightAnim:Stop()
	end

end)

Changing the camera when wallrunning only works when running on the right and left walls in world space and not on all walls. Thanks for any help.

I would either slightly reduce the angle (i.e. 269 instead of 270, 89 instead of 90).

On around Line 248 of the CameraService module, there’s this:

--> Allow clipping through transluscent parts
	if landRay and landRay.Distance and landRay.Instance then 
		if landRay.Instance:IsA("BasePart") then
			zoom = landRay.Instance.Transparency <= 0.4 and landRay.Distance * 0.91 or currentZoom
		else
			zoom = landRay.Distance - 1
		end
	end

You may want to change that 0.91 to something smaller to fit your needs, like 0.85.

1 Like