Lerp problem help

I am attempting to create a lerp camera. While testing it in Roblox Studio, it performs admirably. However, upon testing it in the actual Roblox game environment, I encountered discrepancies. Despite publishing the project, the issue persists.

here’s a clip.

1 Like

the camera script.

while true do task.wait()
	Camera.CameraType = Enum.CameraType.Scriptable
	
	if Character() then
		local AlphaNum = 0.2
		local add = 0
		if Vector3.new(Character().PrimaryPart.Velocity.X, 0, Character().PrimaryPart.Velocity.Z).Magnitude > 20 then
			AlphaNum = 0.075
			add = 40
		end
		Camera.FieldOfView = Lerp(Camera.FieldOfView, 50 + add + Vector3.new(Character().PrimaryPart.Velocity.X, 0, Character().PrimaryPart.Velocity.Z).Magnitude/5, AlphaNum)
		
		local FinalCFrame = CFrame.new(
			Character().PrimaryPart.Position + Vector3.new(0, 7.5, 12.5)
		)
		if Vector3.new(Character().PrimaryPart.Velocity.X, 0, Character().PrimaryPart.Velocity.Z).Magnitude >= 20 then
			FinalCFrame = CFrame.new(
				Character().PrimaryPart.Position + Vector3.new(0, 4.5, 5.5)
			)
		end
		local LookCFrame = Character().PrimaryPart.Position + Vector3.new(0, 0, -5)
		
		if LookBack.Value then
			FinalCFrame = CFrame.new(
				Character().PrimaryPart.Position + Vector3.new(0, 7.5, -12.5)
			)
			if Vector3.new(Character().PrimaryPart.Velocity.X, 0, Character().PrimaryPart.Velocity.Z).Magnitude >= 20 then
				FinalCFrame = CFrame.new(
					Character().PrimaryPart.Position + Vector3.new(0, 4.5, -5.5)
				)
			end
			LookCFrame = Character().PrimaryPart.Position + Vector3.new(0, 0, 5)
			
		end
		
		local PosCFR = Camera.CFrame:Lerp(FinalCFrame, 0.15)
		local CamBodyDistance = (Camera.CFrame.Position - Character().PrimaryPart.Position).Magnitude
		if CamBodyDistance >= 22 then
			--PosCFR = Camera.CFrame:Lerp(FinalCFrame, 0.35)
		elseif CamBodyDistance <= 17 then
			PosCFR = Camera.CFrame:Lerp(FinalCFrame, 0.35)
		end
		
		Camera.CFrame = Camera.CFrame:Lerp(
			CFrame.new(PosCFR.Position) * CFrame.new(
			Camera.CFrame.Position,
			LookCFrame
			).Rotation, 0.25
		)
	end
end	

I don’t know if this is for sure your problem, but you should use BindToRenderStep when doing camera updates.

e.g. instead of while true do, do something like:

local RunService = game:GetService("RunService")

local function UpdateCamera(dt: number)
   -- your code
end

RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, UpdateCamera)
1 Like