I want the first-person camera to follow the head in the animation. I already have the body visible.
Here is the issue. Seeing the animation in third person doesn’t matter because it’s going to be locked in first person when the game comes out. Third person is just for testing.
The youtube tutorials that I found all used moon animator which didn’t work out because I used the default roblox animator. The other forum posts that I found had variables that I didn’t know of so I wasn’t sure where to start. Any help would be appreciated .
I see. Yes, Moon Animator is pretty much unreachable for a lot a people because of its high price. But still, what you can do is extract the player’s head position and constantly check if it’s being updated, then add a temporary Camera instance and set the Workspace’s Camera position and rotation as the Camera, then reset it when the process is done.
local Players = game:GetService("Players")
local _Workspace = game:GetService("Workspace")
local workspaceCamera = _Workspace:WaitForChild("CurrentCamera")
workspaceCamera.CameraType = Enum.CameraType.Scriptable
local cameraInstance = Instance.new("Camera")
local player = Players.LocalPlayer
local character = player.Character or player.Character.CharacterAdded:Wait()
local characterHumanoid = character:WaitForChild("Humanoid")
local headPart = characterHumanoid:WaitForChild("Head")
local animation = "animation_path_or_id"
local animationTrack = characterHumanoid:LoadAnimation(animation)
if animationTrack.IsPlaying == true then
cameraInstance.CFrame = CFrame.new(
headPart.CFrame.Position.X - 2,
headPart.CFrame.Position.Y,
headPart.CFrame.Position.Z
)
workspaceCamera.CFrame = cameraInstance.CFrame
end
if animationTrack.Stopped then
workspaceCamera.CameraType = Enum.CameraType.Fixed
end
What I’m doing here is checking if the animation is playing, then throwing the camera’s position two studs behind the player’s camera. If you bump into anything, let me know!
Sorry if I didn’t do something that you said. I have little experience with cameras in roblox studio. I simply cannot make anything camera related work
Also here is the script that operates the animation:
local characterOG = game:GetService("Players").LocalPlayer.Character
local tool = script.Parent
local animationOG = tool:WaitForChild("SeedSow")
local animationTrackOG = characterOG.Humanoid:LoadAnimation(animationOG)
local canRun = true
local debounceTime = 5 -- Change this for a different tool cooldown length
tool.Activated:Connect(function()
if canRun then
canRun = false
animationTrackOG:Play()
local Players = game:GetService("Players")
local _Workspace = game:GetService("Workspace")
local workspaceCamera = _Workspace:WaitForChild("Camera")
workspaceCamera.CameraType = Enum.CameraType.Scriptable
local cameraInstance = Instance.new("Camera")
local player = Players.LocalPlayer
local character = player.Character or player.Character.CharacterAdded:Wait()
local characterHumanoid = character:WaitForChild("Humanoid")
local headPart = characterHumanoid:WaitForChild("Head")
local animation = "125596070891049"
local animationTrack = characterHumanoid:LoadAnimation(animation)
if animationTrack.IsPlaying == true then
cameraInstance.CFrame = CFrame.new(
headPart.CFrame.Position.X - 2,
headPart.CFrame.Position.Y,
headPart.CFrame.Position.Z
)
workspaceCamera.CFrame = cameraInstance.CFrame
end
if animationTrack.Stopped then
workspaceCamera.CameraType = Enum.CameraType.Fixed
end
wait(debounceTime)
canRun = true
end
end)
I probably should have shared the script beforehand, but at least now it has your revisions.
Just do:
And next time analyze the code and not blantly copy and paste it
User gave you honestly if being polite not good code.
here me debloatwared your code:
--!optimize 2
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Heartbeat = RunService.Heartbeat
local Camera:Camera = workspace.CurrentCamera
local tool:Tool = script.Parent
local Plr:Player = Players.LocalPlayer
local Char:Model = Plr.Character
local Head = Char:WaitForChild("Head")::Part
local Humanoid = Char:WaitForChild("Humanoid")::Humanoid
local Animator = Humanoid:WaitForChild("Animator")::Animator
local animationOG = tool:WaitForChild("SeedSow")::Animation
local animationTrackOG:AnimationTrack = Animator:LoadAnimation(animationOG)
local CanRunDB:boolean = true
local debounceTime:number = 5 -- Change this for a different tool cooldown length
local TaskHeartbeat:RBXScriptConnection? = nil
tool.Destroying:Once(function():()
if TaskHeartbeat~=nil then
TaskHeartbeat:Disconnect()
TaskHeartbeat=nil
end
end)
local function LockToHead():()
Camera.CFrame=Head.CFrame
end
tool.Activated:Connect(function():()
if CanRunDB then
CanRunDB = false
animationTrackOG:Play()
TaskHeartbeat = Heartbeat:Connect(LockToHead)
Camera.CameraType=Enum.CameraType.Scriptable
LockToHead()
task.wait(debounceTime)
if TaskHeartbeat~=nil then
TaskHeartbeat:Disconnect()
TaskHeartbeat=nil
end
CanRunDB=true
Camera.CameraType=Enum.CameraType.Fixed
end
end)
Thank you so much! This worked very well. In the future, I will not copy and paste code. I tried to understand the previous code, but I don’t understand cameras that well. Thanks for the help !