So i have an emote system in my game, But im currently trying to figure out how to make the camera kind of move toward your head, but delay behind a little, but also have some camera limits, so it wont follow the head if the head is pretty far away.
I’m trying to make it like Nico’s Nextbots.
Example:
-- parent -- game -> StarterPlayer -> StarterCharacterScripts
task.wait(.5)
local run = game:GetService("RunService")
local cam = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local cam_offset = CFrame.new()
local lerp_time = 0.3
local function update_cam(dt)
cam_offset = cam_offset:Lerp(CFrame.new() + (hrp.CFrame + Vector3.new(0, 1.5, 0)):ToObjectSpace(head.CFrame).Position, lerp_time)
hum.CameraOffset = cam_offset.Position
end
run.RenderStepped:Connect(update_cam)
and here’s a version that is immediate:
-- parent -- game -> StarterPlayer -> StarterCharacterScripts
task.wait(.5)
local run = game:GetService("RunService")
local cam = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local function update_cam(dt)
hum.CameraOffset = (hrp.CFrame + Vector3.new(0, 1.5, 0)):ToObjectSpace(head.CFrame).Position
end
run.RenderStepped:Connect(update_cam)
-- parent -- game -> StarterPlayer -> StarterCharacterScripts
task.wait(.5)
local run = game:GetService("RunService")
local cam = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
local hrp = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local cam_offset = CFrame.new()
local lerp_time = 0.3 -- can be a value between 1 and 0, 1 being immediate, 0 being infinitely slow
-- closer value get's to 0 the slower the camera lerps
local cam_offset_enabled = true
local function update_cam(dt)
local to_lerp_cframe = (cam_offset_enabled and CFrame.new() + (hrp.CFrame + Vector3.new(0, 1.5, 0)):ToObjectSpace(head.CFrame).Position) or CFrame.new(0, 0, 0)
cam_offset = cam_offset:Lerp(to_lerp_cframe, lerp_time)
hum.CameraOffset = cam_offset.Position
end
run.RenderStepped:Connect(update_cam)
when cam_offset_enabled = true the camera will lerp to the heads position like it did originally and when false it will lerp back to 0, 0, 0