hi y’all,
i’ve been fiddling with this camera script that makes my game function kind of like a 2d platformer by setting the camera up to be a certain x value away from the humanoid root part every frame. i’ve also tried to make a environment based fov system that works in unison with the position of the camera by tweening the camera’s fov based on a part the humanoid root part is touching using the :GetTouchingParts() function, but it doesnt return anything or get what i want done. any ideas? screenshots and my code is down below.
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local ts = game:GetService("TweenService")
local triggers = game.Workspace.triggers
player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")
camera.CameraSubject = player.Character:FindFirstChild("HumanoidRootPart")
camera.CameraType = Enum.CameraType.Scriptable
--camera.FieldOfView = 25
game:GetService('RunService').Stepped:Connect(function()
local rootpart = camera.CameraSubject
local touchingtable = rootpart:GetTouchingParts()
for i,v in pairs(touchingtable) do
print(v.Name)
if v.Parent == triggers then
local fieldofviewnecessary = v:FindFirstChildOfClass("NumberValue").Value
print(v.Name.." "..fieldofviewnecessary)
local goal = {}
goal.FieldOfView = fieldofviewnecessary
ts:Create(camera, TweenInfo.new(1), goal):Play()
end
end
camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,5,45)
camera.CFrame = CFrame.lookAt(camera.CFrame.Position, player.Character.HumanoidRootPart.Position)
end)