Immersive Camera System - Take your game to the next level!

Are you tired of the traditional camera system in your game? Want to add a custom camera system to your game? Look no further! I am excited to announce the release of my custom immersive camera system that you can use freely in your own games.

The immersive camera system allows players to control the camera and point it towards the direction they are looking, as well as switch to focus on special objects. This can enhance the overall gaming experience and improve the player’s experience.

You can use this system for a variety of game genres, from action-adventure to sports and racing games. It can be used to replicate the camera system used in popular games like Rocket League, or to create unique camera perspectives in your own game.

I’ve provided showcase videos to help you get a better understanding of how this immersive camera system works and how it can enhance the overall gaming experience. I hope you’ll find it useful.

Camera type 1: (Face directional)

Camera type 2: (Object directional)


Adding it to your game:

  1. Create a new local script in the StarterCharacterScripts and paste the provided code into it.
  2. Make sure that you have the necessary objects in your game for the script to reference, such as a “Ball” object in the “workspace” and a “HumanoidRootPart” object within the player character.
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

-- Create a new camera object and set it as the parent of the player character
local camera = Instance.new("Camera")
camera.Parent = character

-- Get the object that should be lerped to
local ball = workspace.Ball

-- Set the camera as the active camera for the game
workspace.CurrentCamera = camera

-- Create a variable to store the last camera position
local lastCFrame = CFrame.new()

-- Create a variable for the smoothness of the camera movement
local smoothness = 0.3

-- Create a variable to track the current camera type (1 or 2)
local cameraType = 1

-- Create a variable to track the zoom level of the camera
local zoom = 0

-- Create a function to update the camera's position
local function Update(dt)
	-- Get the humanoid root part of the character
	local root = character:WaitForChild("HumanoidRootPart")

	-- Check if the character is in a state of freefall, jumping, flying, or falling down
	if humanoid:GetState() == (Enum.HumanoidStateType.Freefall or Enum.HumanoidStateType.Jumping or Enum.HumanoidStateType.Flying or Enum.HumanoidStateType.FallingDown) then
		-- Set the zoom level to 3 if in a falling state
		zoom = 3
	else
		-- Set the zoom level to 0 if not in a falling state
		zoom = 0
	end

	-- Check the current camera type
	if cameraType == 1 then
		-- Get the look vector of the character and adjust it to only move in the x and z planes
		local lookVector = (root.CFrame.lookVector * Vector3.new(1, 0, 1)).unit

		-- Calculate the target camera position and rotation
		local targetCFrame = CFrame.new(root.Position - lookVector * (12 + zoom), root.Position + lookVector) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)) * CFrame.new(0, 3, 0)

		-- Interpolate the camera's position and rotation to the target values using the smoothness variable
		camera.CFrame = lastCFrame:Lerp(targetCFrame, smoothness * dt * 60)
	else
		-- Calculate the horizontal offset of the camera from the ball
		local horizontalAdd = (root.Position - Vector3.new(ball.Position.X, root.Position.Y, ball.Position.Z)).Unit
		local camPos = root.Position + horizontalAdd * 12 + Vector3.new(0, 4)

		-- Create a target camera position that looks at the ball
		local targetCFrame = CFrame.lookAt(camPos, ball.Position)

		-- Interpolate the camera's position and rotation to the target values using the smoothness variable
		camera.CFrame = lastCFrame:Lerp(targetCFrame, smoothness)
	end

	-- Update the lastCFrame variable with the current camera position
	lastCFrame = camera.CFrame
end

-- Connect the update function to the RenderStepped event
game:GetService("RunService").RenderStepped:Connect(Update)

-- Connect to the InputBegan event on the UserInputService
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(key, processed)

	-- Check if the input has already been processed
	if processed then
		return
	end

	-- Check if the spacebar was pressed
	if key.KeyCode == Enum.KeyCode.Space then

		-- Switch between camera types
		if cameraType == 1 then
			cameraType = 2
		else
			cameraType = 1
		end

	end

end)


Customization

Once you have successfully added the immersive camera system to your game, you may want to customize it to suit your specific needs. Here are some tips on how you can customize the camera system:

  1. Adjust the smoothness variable: The smoothness variable controls how smoothly the camera moves between different positions. You can adjust this variable to make the camera movements more or less smooth.
  2. Adjust the zoom variable: The zoom variable controls the distance of the camera from the player character. You can adjust this variable to make the camera zoom in or out.
  3. Change the camera type: The provided code includes two camera types, one that follows the player’s look direction and one that focuses on the “Ball” object. You can change the camera type by pressing the spacebar key. You can also add more camera types or modify the existing ones according to your game’s needs.
  4. Modify the camera’s position and rotation: The camera’s position and rotation are determined by the CFrame values in the code. You can modify these values to change the camera’s position and rotation in your game.
  5. Add special effects: You can add special effects such as blur or shake to the camera to enhance the immersive experience.
  6. Changing the key that’s used to switch the camera type: By default, the script uses the Spacebar key to switch between camera types. You can change this key to any other key by changing the Enum.KeyCode.Space to the desired keycode.
  7. Enable and Disable the camera system: You can add a button in your game to enable and disable the camera system.

By customizing the immersive camera system, you can create a unique camera experience that perfectly fits your game’s needs.


Conclusion

In conclusion, I hope that this custom immersive camera system will enhance your game experience and take it to the next level. I won’t be updating this script in the future, but I will do my best to address any bugs that may occur. Please feel free to customize and tweak the script to fit your game’s specific needs.

Special thanks to @Daimywil for helping me figure out the binding of the 2nd camera view in this forum post.

28 Likes

You should make this smoothness * dt * 60 for FPS unlocker compatibility.

1 Like

I don’t have time right now to test whether this is an improvement, but I trust your lifting of it and will change it.

Thank you for bringing this to my attention.

Very nice system. Something I recommend is for this system to be written as a OOP module for added organization and for the system to be more dynamic using OOP.

2 Likes