Enhanced Camera System - Easy-to-use "Shift Lock" / "Over-the-shoulder" camera module with collision detection

About Enhanced Camera System

Using original “Shift Lock” camera mode from Roblox might sometime cause wall-clipping issue when character standing too close to a wall or a big object. In order to get rid of the wall-clipping is to create a custom camera script for achieve a better “Shift Lock” mode and this is the reason I wanted to create this module.

Enhanced Camera System is a user-friendly, multi-functional camera module that can be easily implemented into any game and act as an alternative method to achieve a customizable over-the-shoulder camera with proper collision detection.

  • Easy Setup
  • Customizable
  • Smooth Transition
  • Mobile Compatible
  • Collision Detection
  • Compatible to most games (Using default Roblox camera script - CameraType.Custom)

Enhanced Camera System Module

The module is placed under the tool for easy plug & play demonstration and it should be configured as below setup for further application - or you might find the module here: GitHub

https://www.roblox.com/library/6562513266/Enhanced-Camera-System

Update Log
  • Redefining “local Character = Player.Character” in all functions to ensure overall module stability
  • Added a separate function to toggle mouse icon
  • Moved RaycastParams out of RenderStep function to improve performance
  • Added mouse sensitivity adjustment in different camera modes for better controls

Module Setup

  1. Place the module into StarterPlayerScripts
  2. Put below code into LocalScript anywhere you would like to switch camera modes from
 local Players = game:GetService("Players")
 local Player = Players.LocalPlayer
 local ECS = require(Player.PlayerScripts:WaitForChild("EnhancedCameraSystem"))

MouseIcon(Status)

To toggle mouse icon

ECS:MouseIcon(true)
ECS:MouseIcon(false)

MouseLock(Status)

To toggle moving-camera-without-right-clicking mode as well as locking mouse at center of screen (Is there a better name to describe this?)

ECS:MouseLock(true)
ECS:MouseLock(false)

Alignment(Status)

To toggle character alignment that facing forward as the camera angle

ECS:Alignment(true)
ECS:Alignment(false)

CameraMode(Mode)

To toggle different camera modes as well as resetting camera

ECS:CameraMode("Aim")
ECS:CameraMode("FirstPerson")
ECS:CameraMode("Scope")
ECS:CameraMode("Reset")

Usage Sample

A simple script that put under StarterCharacterScripts to toggle over-the-shoulder camera when holding down right mouse button

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local ECS = require(Player.PlayerScripts:WaitForChild("EnhancedCameraSystem"))

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function (input)
  
   if input.UserInputType == Enum.UserInputType.MouseButton2 then
       ECS:MouseLock(true)
       ECS:Alignment(true)
       ECS:CameraMode("Aim")
   end

end)

UserInputService.InputEnded:Connect(function (input)
  
   if input.UserInputType == Enum.UserInputType.MouseButton2 then
       ECS:MouseLock(false)
       ECS:Alignment(false)
       ECS:CameraMode("Reset")
   end

end)

Test Place & Application

You might try the camera system here at the test place below :raised_hands:

https://www.roblox.com/games/6211585678/

Notes

Thank you so much for your time! I just started learning about scripting not long ago and this is my first attempt to create a module script. :bowing_man: I hope this small module script could assist your projects. Feel free to let me know for any questions, suggestions or encountered bugs.

100 Likes

Really nice! Could you kindly upload a video displaying this? Plus - controller support would be really nice!

3 Likes

Thanks much! I have just added some basic demonstration videos into the post and it might to help display the basic functions of this module :raised_hands: Let me also take a look into controller controls :bowing_man:

I love this! Also if you’d want making the place uncopylocked so people can better understand how to use it could help

1 Like

This looks really nice!

Custom camera modules are surprisingly lacking, and I really like that you took it upon yourself to fix issues and also put your own twist on it.

You might consider uploading your code to GitHub, to allow people to look at the functionality without entering Studio. Do you have any plans to update/add features to the camera system at a later point?

1 Like

Simple, useful, and very neat. Overall an impressive module. A few suggestions are to avoid making so many mini-namecalls. For example:

function ECS:MouseCameraOn() --Enable moving-camera-without-right-clicking mode
	
	isSteppedIn = true
	UserInputService.MouseIconEnabled = false
	
end

function ECS:MouseCameraOff() --Disable moving-camera-without-right-clicking mode

	isSteppedIn = false
	UserInputService.MouseIconEnabled = true

end

Can be easily replaced by something like:

function ECS:SetMouseCamera(Status) --Enable moving-camera-without-right-clicking mode
	
	isSteppedIn = Status
	UserInputService.MouseIconEnabled = not Status
	
end
4 Likes

Thank you so much for this! I was stuck trying to collide the camera with shiflock. This saved my life, thank you again!

1 Like

Ohh yes! That definitely would look more clean and convenient to use :raised_hands: I will try revising the module with the same approach Thanks much for the suggestion!

2 Likes

Thank you! :pray: I will try uploading it into GitHub after making some adjustments on the module.

For future, I was thinking a camera bobbing feature for sprinting could also done within the structure :pray:

2 Likes

Thank you! :raised_hands: I will try putting the module and a sample tool together into the model in next update and it might be easier to try the module with the tool that came along

1 Like

I did a small update on the module script structure and it should be more clean and easy to use than before :raised_hands: Special thanks to @OminousVibes0 :pray:

The module is now also placed under a sample tool in the model for quick demonstration once it’s inserted into studio :muscle:

2 Likes

I merged this module with fastcast to make a pretty decent laser gun.
Note: I did a rush job, the code isn’t the most efficient. Feel free to make edits.
I believe I will be using this module a lot in the future.
CameraTest.rbxl (95.2 KB)

Suggestions:

  • Change ECS:MouseCamera() to ECS:MouseLock()
  • Take Raycast parameters out of RenderStepped, because you are making an identical parameter for every render.
  • Have you considered using Camera:GetPartsObscuringTarget()? It’s similar to the raycast you are doing right now.
  • For some reason, the cursor disappears during a few Camera modes (not sure if that is intentional) but could you make the cursor adjustable? This would be especially useful for the “Aim” mode.

Overall a really good module, I hope you can add a few of these suggestions to improve performance and Customizeability.

3 Likes

Thanksss! I made some updates on the modules based on your suggestions :raised_hands:

For Camera:GetPartsObscuringTarget(), somehow it doesn’t return the “Hit” position and couldn’t used for calculating the collision position from its first return value. Raycasting might be a better option in this case :muscle:

3 Likes

Hey, I’m experiencing a small bug while using this module in-game. The camera works just fine while the tool is equipped, but once you begin aiming with it and looking around, it twitches akwardly. I’m not sure what specifically is causing this as the only part of the module I edited was the offset.

I’ve also got my code that enables/disables it here,

-- Connection 1 --
local function ConnectOne()
	Connection_1 = Tool:GetAttributeChangedSignal("IsAiming"):Connect(function()
		local IsAiming = Tool:GetAttribute("IsAiming")
		
		
		if IsAiming then
			OTS:CameraMode("Aim")
			OTS:Alignment(true)
			OTS:MouseIcon(true)
			
		else
			OTS:CameraMode("Reset")
			OTS:Alignment(false)
			OTS:MouseIcon(false)
			
		end
		
		
	end)
end
--				--

Along with two basic Tool.Equipped and Tool.Unequipped functions that run,

(equipped)

OTS:MouseIcon(false)
OTS:MouseLock(true)

(unequipped)

OTS:CameraMode("Reset")
OTS:Alignment(false)
OTS:MouseIcon(true)
OTS:MouseLock(false)

If you could offer any help, it’d be greatly appreciated.

1 Like

Don’t forget the Controller(Xbox)

or input.KeyCode == Enum.KeyCode.ButtonL2 – For Aim Down Sight

1 Like

Hi Aensvey, sorry for such late response! I haven’t been on the platform for a while recently. My apologies!

I have took a look on the weapon system and felt that there was some delay on the character alignment. The character alignment was meant to be done from client and it should be no delay under normal circumstance. Might I know would you mind to make use of the original unedited module script to see if the issue still occur?

Below is the part of code for the character alignment adjustment under the module

RunService.RenderStepped:Connect(function()

		local rx, ry, rz = CurrentCamera.CFrame:ToOrientation()
		HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.fromOrientation(0, ry, 0)

end)

In the module, Character is always defined as Player.Character however this doesn’t work if the character has not loaded in yet, so instead I recommend doing Character = Player.Character or Player.CharacterAdded:Wait() as this will account for that.

1 Like

Module has been updated in terms of functionality - The “LockCenter” camera mode can be reset without issue now :raised_hands:

How do i apply this to shiftlock for smooth transition, i’m having trouble applying this to playermodule, could you write a guide if you don’t mind

This is BEAUTIFUL. Thank you kindly. So so much