Issues making the "CameraOffset" track properly

So, I wanted to recreate a camera system, where it follows the character in delay. I wanna use CameraOffset (The local Humanoid property, which adds offset to the camera, when the subject is the Humanoid.), however I cant really seem to get the offset to work how I want to (it sometimes gets offsetted to the left more and also just doesn’t allow for the player to spin around well)

How it looks like right now:

External Media

My script:

local Character = script.Parent

local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")

local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Transparency = 0.5
p.CFrame = RootPart.CFrame
p.Parent = Character
p.Size = Vector3.new(0.5,0.5,0.5)

RunService.RenderStepped:Connect(function()
    p.CFrame = p.CFrame:Lerp(RootPart.CFrame,0.25)
    local Offset = Vector3.new(0,0,0)
    if (RootPart.Position - p.Position).Magnitude >= 0.02 then
        Offset = CFrame.lookAt(RootPart.Position,p.Position).LookVector
    end
    Humanoid.CameraOffset = Humanoid.CameraOffset:Lerp(Offset,0.15)
    

end)

Have you searched the forums for a solution?
I’m definitely no pro when dealing with this, but I just tried googling roblox tutorial camera spring scripting and found quite a few videos and forum posts about this subject.

I’ve seen a variant of this where it sets the subject as the part that follows, however that erradicates first person and shift lock. Though, you reminded me about Spring Modules, and I think those could do the trick.

1 Like

Still haven’t figured it out, and I really dont know what I’m doing wrong with the CameraOffset.

I’m pretty sure this was caused because you were getting the offset in world space instead of the object space, which made the camera move in the wrong direction (ej. if you were moving left in the world space, and your character was facing the left, then it SHOULD be the front of your character, but it would still move to the left because its not relative to it)

My code

--!strict
local RunService = game:GetService("RunService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local root = character:WaitForChild("HumanoidRootPart") :: Part
local oldCFrame = root.CFrame

RunService.RenderStepped:Connect(function(dt: number)
	local currentCFrame = root.CFrame
	local offset = currentCFrame:ToObjectSpace(oldCFrame)
	
	humanoid.CameraOffset = humanoid.CameraOffset:Lerp(offset.Position * 2, dt * 5)
	oldCFrame = currentCFrame
end)
1 Like

You were right! Thank you for the assistance

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.