Offsetting the camera

I’m trying to make a very similar trail effect with the camera offset. But I just can’t seem to get it to work right.

This is the goal:

Here is my code, but it just doesn’t seem to be the same way:

local smoothingSpeed = 8 

game:GetService("RunService").RenderStepped:Connect(function(dt)
	local vel = rootPart.Velocity
	local walkspeed = char.Humanoid.WalkSpeed

	local horizontalVel = Vector3.new(vel.X, 0, vel.Z)
	local speed = horizontalVel.Magnitude

	local moveDir = speed > 0.1 and horizontalVel.Unit or Vector3.zero
	local trailDistance = 3 * speed / (walkspeed * 2)
	local worldOffset = -moveDir * trailDistance

	local localOffset = rootPart.CFrame:VectorToObjectSpace(worldOffset)
	local verticalOffset = math.clamp(vel.Y / 30, -5, 5)
	local targetOffset = Vector3.new(localOffset.X, verticalOffset, localOffset.Z)

	local currentOffset = char.Humanoid.CameraOffset
	local alpha = 1 - math.exp(-smoothingSpeed * dt)
	char.Humanoid.CameraOffset = currentOffset:Lerp(targetOffset, alpha)
end)
1 Like

If you don’t want to use a custom camera type or fixed camera type, it will be absolutely necessary to edit the camera module. It’s not that hard. Just change the part where it sets the CFrame to lerp instead.

I did take a look at the module, but was unable to locate the CFrame that is being set.

It’s difficult to locate, and it’s been a while since I’ve modified it. It might be in a module called BaseCamera though. It’s in one of them.

1 Like

Thank you so much! This is what I did:

  1. Made a copy of the camera from the roblox.
  2. Opened the BaseCamera module
  3. In the GetSubjectPosition I changed:
result = bodyPartToFollow.CFrame.p + bodyPartToFollow.CFrame:vectorToWorldSpace(heightOffset + cameraOffset)

too:

local targetPosition = bodyPartToFollow.CFrame.p + bodyPartToFollow.CFrame:vectorToWorldSpace(heightOffset + cameraOffset)
result = result:Lerp(targetPosition, 0.1)

Quick question, since I made a copy of the entire camera script and put it into StarterPlayerScripts will there be any issues?

1 Like

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