I have a 3rd person camera, which I want to be able to change dynamically as players move around the map.
I’m unsure how to plugin this LookVector tho. Basically, the camera needs to rotate once I touch a specific part. Ideally it’d lerp slower around too. I set the lerp to high because when the camera is in a solid 3rd person look, it should stay reasonable close to the exact position, but when rotating, i dont want it to immediately snap
So touching blue would set lookvector back to 0,0,0, but touching the pink should make camera rotate on that lookvector (can see cone handle for orientation)
local OFFSET = Vector3.new(-15, 6, 0)
local INTERIOR_OFFSET = Vector3.new(-15, 9, 0)
local FOV = 65
local CameraLookVector = Vector3.new(0, 0, 0)
--// Get the default position for the camera
function CameraController:GetDefaultPosition()
local Character = game.Players.LocalPlayer.Character
if not Character then return end
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return end
local PlayerPosition = HumanoidRootPart.Position
local CameraPosition = PlayerPosition + (game.Players.LocalPlayer:GetAttribute("Inside") and INTERIOR_OFFSET or OFFSET)
return PlayerPosition, CameraPosition
end
--// Update camera movement
function CameraController:Update()
-- Get default position
local PlayerPosition, CameraPosition = self:GetDefaultPosition()
if not PlayerPosition or not CameraPosition then return end
local To = CFrame.new(CameraPosition, PlayerPosition)
CurrentCamera.CFrame = CurrentCamera.CFrame:Lerp(To, 0.5)
end
for _, v in pairs(CollectionService:GetTagged("Camera")) do
v.Touched:Connect(function(hit)
local Character = hit.Parent
if not Character then return end
local TouchedPlayer = game.Players:GetPlayerFromCharacter(Character)
if not TouchedPlayer then return end
if TouchedPlayer ~= game.Players.LocalPlayer then return end
CameraLookVector = v.LookVector
end)
end