Hi all! I’m working on an RPG-ish game camera and currently I’m setting the CFrame of the camera to the player’s HumanoidRootPart + an offset managed by a Vector3 variable I wanted to edit the offset (and the FOV, optionally) depending on the area the player is in…
I thought of doing this by using a non-collideable box that would act as trigger and a Vector3 variable as the part’s children, I can’t get it to work though, any idea on how I could do it or a better method?
local defaultCameraOffset = Vector3.new(0,15,25)
local defaultFOV = 40
local cameraOffset = defaultCameraOffset
local currentFOV = defaultFOV
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 = currentFOV
if Character then
if Character:FindFirstChild("HumanoidRootPart") then
game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, Character.Head)
Camera.CFrame = CFrame.lookAt(Character.HumanoidRootPart.Position + cameraOffset , Character.HumanoidRootPart.Position)
end
end
end)
-- handle respawn
Player.CharacterAdded:Connect(function(char)
Character = char
end)
Here’s some footage of what I’ve achieved so far
This is what I’ve done so far, it’s a slightly modified version of a youtube tutorial, I wanted the camera to
- transition smoothly from one vector offset to the other
- have the modified vector offset only when the player is colliding with any part that has a way to be identified as a camera trigger (I was thinking of naming all the triggers the same way and check that)
please keep in mind that I’m an absolute beginner with both lua and roblox scripting, while I have experience with other languages I still can’t get the hang of lua, sorry!