How Do I Make The Camera Follow The Player When An Animation Is Played?

Just like the title says, how does one make the camera follow the player when an animation is played? I have made a vault script and animation but whenever the player vaults the camera stays where the player has vaulted during the animation. Please help me!!!

Script:

local player = game:GetService(“Players”).LocalPlayer
local Character = player.Character
Character:WaitForChild(“HumanoidRootPart”)
local humanoid = Character:WaitForChild(“Humanoid”)
if script.DisableJump.Value then
humanoid.JumpPower = 0
end
–warn(“PASSED”) --DEBOUNCE! when true, it is available for move. when false, busy
local debounce = true

–GUIS
local vaultGui = script.Vault.BillboardGui
local vaultEnabled = false

–ANIMS
local vaultAnim = humanoid:LoadAnimation(script.Vault.anim)

local RS = game:GetService(“RunService”)
local IS = game:GetService(“UserInputService”)
local TS = game:GetService(“TweenService”)

local part = nil

local vaultDetector = Instance.new(“Part”, game.Workspace)
vaultDetector.CanCollide = false
vaultDetector.Transparency = 1 – Change to 0 for debug, but otherwise keep 1
vaultDetector.Size = Vector3.new(2,1,4)
vaultDetector.CFrame = Character.HumanoidRootPart.CFrame
vaultDetector.Massless = true

local Weld = Instance.new(“Weld”, vaultDetector)
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = vaultDetector
Weld.C1 = CFrame.new(0, -0.25, 2)
Weld.C0 = CFrame.new()

local function vaultGuiUpdate(part)
–print(“part”)
if vaultEnabled then
local cloneGui = vaultGui:Clone()
cloneGui.Parent = part
cloneGui.Enabled = true
else
if part:FindFirstChild(vaultGui.Name) then
part:FindFirstChild(vaultGui.Name):Destroy()
end
end
end

local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
for index, value in ipairs(results) do
if value:FindFirstChild(“IDENTIFIER”) ~= nil and value.IDENTIFIER.Value == “ParkourPart” and value.Vaultable.Value then
return value
end
end

return nil
end

local function playerInput(key, processed)
if not processed and debounce then

	if key.KeyCode == Enum.KeyCode.Space then
		if vaultEnabled then
			debounce = false
			Character.HumanoidRootPart.Anchored = true
			local xCalc = (prevPart.CFrame.Position.X-Character.HumanoidRootPart.CFrame.Position.X)*2
			local zCalc = (prevPart.CFrame.Position.Z-Character.HumanoidRootPart.CFrame.Position.Z)*2
			Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(Character.HumanoidRootPart.CFrame.Position.X,Character.HumanoidRootPart.CFrame.Position.Y,Character.HumanoidRootPart.CFrame.Position.Z),Vector3.new(Character.HumanoidRootPart.CFrame.Position.X+xCalc, Character.HumanoidRootPart.CFrame.Position.Y, Character.HumanoidRootPart.CFrame.Position.Z+zCalc))
			local tweenInfo = TweenInfo.new(vaultAnim.Length)
			local goal = {}
			goal.CFrame = CFrame.new(Vector3.new(Character.HumanoidRootPart.CFrame.Position.X+xCalc, Character.HumanoidRootPart.CFrame.Position.Y, Character.HumanoidRootPart.CFrame.Position.Z+zCalc), Vector3.new(Character.HumanoidRootPart.CFrame.Position.X+xCalc*2, Character.HumanoidRootPart.CFrame.Position.Y, Character.HumanoidRootPart.CFrame.Position.Z+zCalc*2))
			--vaultAnim:Play()
			local tween = TS:Create(Character.HumanoidRootPart,tweenInfo,goal)
			
			vaultAnim:Play()
			--vaultAnim.Stopped:Wait()
			wait(vaultAnim.Length-0.5)
			--vaultAnim:Stop()
			--tween:Play()
			Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(Character.HumanoidRootPart.CFrame.Position.X+xCalc, Character.HumanoidRootPart.CFrame.Position.Y, Character.HumanoidRootPart.CFrame.Position.Z+zCalc), Vector3.new(Character.HumanoidRootPart.CFrame.Position.X+xCalc*2, Character.HumanoidRootPart.CFrame.Position.Y, Character.HumanoidRootPart.CFrame.Position.Z+zCalc*2))
			vaultAnim:Stop()
			Character.HumanoidRootPart.Anchored = false
			debounce = true
		end
	end
	
end

end

local function heartbeat() --Runs once every server frame
part = GetTouchingParts(vaultDetector)

--print(part)
if part ~= nil then
	prevPart = part
	if vaultEnabled == false then
		vaultEnabled = true
		vaultGuiUpdate(part)
	end
else
	if vaultEnabled == true then
		vaultEnabled = false
		vaultGuiUpdate(prevPart)
	end
end	

end

RS.Heartbeat:connect(heartbeat)
IS.InputBegan:connect(playerInput)

2 Likes

From looking at your post, I suggest you post your code and relevant information so people can help you!

Without much information I am left able to only do this; here are some resources relevant to this question:

1 Like

The camera’s subject is your HumanoidRootPart. The HumanoidRootPart doesn’t change while your animation is playing so I suggest you change the camera’s subject to your player’s Head with a LocalScript. That way, the camera will move according to your head’s position the way you wanted.

7 Likes

When you do this and zoom into first person the character doesn’t turn at all.