I need help with my camera system

Ok so i am making a single player story exploration game and i want to use an interesting camera technique Older Resident Evil games use! My main camera is a isometric camera view but i would like to make it so when i am touching a part / area my camera would lock onto another part making a fixed camera angle.

I have tried researching many things and using chat GPT (to see if it could detect any errors) but nothing seems to work.

This is what it looks like

Here is my current camera script! for some reason it doesn’t want to work with any other scripts.

-- --//Settings//--
local zoom = 120
local FieldOfView = 7


local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Custom

local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
	Camera.FieldOfView = FieldOfView
	if Character then
		if Character:FindFirstChild("Head") then
			game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, Character.Head)
			Camera.CFrame =
				CFrame.new(Vector3.new(Character.Head.Position.X + zoom, Character.Head.Position.Y + zoom, Character.Head.Position.Z + zoom), Character.Head.Position)
		end
	end
end)

I am not very good at coding so if anyone could help that would be awesome Thanks!!

5 Likes

You can tween the camera to a welded part on the player then set the focus to the player. You can use character added and instance.new to create a part and a weld which is welded to the player.

1 Like

You have most of it, but you need to change the 2nd parameter of CFrame.new to the part that you want the camera to look at. Also, you should use CFrame.lookAt instead.

It’s surprisingly easy if you do it correctly, you just detect if a player touches a part, then tween it’s camera into an anchored “camera part” to then await another touched event:

For this template example, it will be awaiting a Touched event from a part, then the player’s camera will be tweened to the part’s CFrame.

local TS = game:GetService("TweenService")

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local touchPart = workspace.TouchPart

touchPart.Touched:Connect(function(otherPart)
    if player.Name == otherPart.Parent.Name then
        TS:Create(camera,TweenInfo.new(1,Enum.EasingStyle.Exponential),{CFrame = touchPart.CFrame}):Play()
    end
end)

Let me know if this works.



Edit:

If you’re trying to lock the player’s camera into a part, and make the part constantly look at the player, you can simply do something like this:

local TS = game:GetService("TweenService")
local RS = game:GetService("RunService")

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local part = workspace.Part

RS.RenderStepped:Connect(function()
    if player.Character and player.Character.HumanoidRootPart then
        part.CFrame = CFrame.lookAt(part.Position,player.Character.HumanoidRootPart.Position)
        camera.CFrame = part.CFrame
    end
end)
1 Like

That’s a lot closer to what i am trying to do but it still doesn’t work.

It’s just a template, you can try doing this in a blank baseplate and just insert the required parts for the script.

I am still struggling to understand sorry. but i made this image if it helps with what i want

Normal Camera always then when touching part it switches, when not touching it switches back to normal

We know what you are trying to do, and we are providing you with example scripts.

Can you try them?

I tried it and nothing happens but my game does give an output when i touch the part. ill keep trying to see if i can get it to work!

EDIT

So i tried the scripts and neither work. They both show that it is detecting me standing on it but nothing happens! maybe i just have it setup wrong? but idk.

i am getting an output error showing this " Workspace.Part.Script:9: attempt to index nil with 'Name’"

1 Like

On line 9 you should instead do:

If otherpart.Parent:FindFirstChild(“Humanoid”) then

This checks if otherpart has a Humanoid, this tells us that otherpart is a player since only player (and NPCs) have humanoids

1 Like

Now i dont get any output and still no camera change

1 Like

Put this in a local script, by the way. That’s probably why it doesn’t work.

Remember to wrap variables around with a :WaitForChild(), as local scripts don’t immediately access the parts in the workspace.

local part = workspace:WaitForChild("Part")

Still no luck unfortunately. Is it usually this difficult to manipulate the camera?

1 Like

It’s not very difficult to change the camera, really.

Here’s an example script, put this inside StarterPlayerScripts and make sure it’s a local script, of course.

local player = game.Players.LocalPlayer

local camera = workspace.CurrentCamera

local cframe = { --You can customise this.
    ["position"] = {0,20,0},
    ["orientation"] = {0,-90,0}
}

camera:GetPropertyChangedSignal("CameraType"):Wait()
camera.CameraType = Enum.CameraType.Scriptable

camera.CFrame = CFrame.new(cframe.position[1],cframe.position[2],cframe.position[3]) * CFrame.Angles(math.rad(cframe.orientation[1]),math.rad(cframe.orientation[2]),math.rad(cframe.orientation[3]))

This just regularly sets the camera to a position and orientation, a CFrame.

1 Like

Ok cool so that works! but now i just need to figure out how to make it change on touch. ill try some stuff out and update you on what happens!

1 Like

Update: i made this script but doesnt seem to work. im really bad at scripting so please bare with me!

i also tried combining the scripts you gave me to see if that would work.

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local cframe = {
	["position"] = {0, 20, 0},
	["orientation"] = {0, -90, 0}
}

camera:GetPropertyChangedSignal("CameraType"):Wait()
camera.CameraType = Enum.CameraType.Scriptable

local touchPart = workspace:WaitForChild("PartActivate")

local isTouching = false

local function lockCamera()
	camera.CFrame = CFrame.new(cframe.position[1], cframe.position[2], cframe.position[3]) * CFrame.Angles(math.rad(cframe.orientation[1]), math.rad(cframe.orientation[2]), math.rad(cframe.orientation[3]))
end

lockCamera()

touchPart.Touched:Connect(function(otherPart)
	if otherPart.Parent == player.Character then
		isTouching = true
		lockCamera()
	end
end)

touchPart.TouchEnded:Connect(function(otherPart)
	if otherPart.Parent == player.Character then
		isTouching = false
	end
end)

Ok so i kinda got it working but this really weird thing happens! when i touch the part the camera changes but my character dies for some reason and then sometimes when i respawn it will flip my character around.

heres a clip

local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera

local triggerPart = game.Workspace:WaitForChild("TriggerPart") -- Replace "TriggerPart" with the actual name of the part you want to use as the trigger

local isLocked = false
local lockedCameraCFrame = CFrame.new(Vector3.new(0, 20, 0), Vector3.new(0, -90, 0)) -- Define the locked camera position and orientation

local function lockCamera()
	isLocked = true
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = nil -- Clear the CameraSubject to stop following the character
	camera.CFrame = lockedCameraCFrame -- Set the camera to the locked position and orientation
end

local function unlockCamera()
	isLocked = false
	camera.CameraType = Enum.CameraType.Custom
	camera.CameraSubject = player.Character.Humanoid
end

triggerPart.Touched:Connect(function(otherPart)
	local character = otherPart.Parent
	local characterHumanoid = character and character:FindFirstChild("Humanoid")

	if characterHumanoid then
		lockCamera()
	end
end)

triggerPart.TouchEnded:Connect(function(otherPart)
	local character = otherPart.Parent
	local characterHumanoid = character and character:FindFirstChild("Humanoid")

	if characterHumanoid and isLocked then
		unlockCamera()
	end
end)

Before it would show a some sort of error thing on my screen saying
“gameplay paused”

1 Like

The camera is so far away from the character that the character and baseplate are getting streamed out. Weird.

1 Like

Ok So i got the camera change working But it still doesnt want to work when i use the Isometric Cam…

Heres A clip.

Does anyone know why its breaking when i use both?

Interesting, you might want to make sure the CFrame isn’t being set to the isometric view if the camera is in the look camera mode.