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.
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!!
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.
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)
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’"
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”