Problems with custom camera and player movement

When the player holds either mouse1 or mouse2 down, their character lerps towards the direction of where their camera is looking towards.
However, this doesn’t work as well when the player is moving backward while holding down left or right mouse, and I’m unsure what the problem is.
https://gyazo.com/d7ed1978c64567b3c5ceb041bdf69e6f

An excerpt from the code

local function SyncHeights(p0, p1)
	local Flat = Vector3.new(1, 0, 1)
	return p0 * Flat, p1 * Flat
end
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function(dt)
	if RMBHeld() or LMBHeld() then
		local TargetPosition = Camera.CFrame.Position + (Camera.CFrame.LookVector * Client.CameraMaxZoomDistance * 2)
		local LookerFrame = CFrame.lookAt(SyncHeights(hrp.Position, TargetPosition))
		local Frame = LookerFrame - LookerFrame.Position + hrp.Position
		
		hrp.CFrame = hrp.CFrame:lerp(Frame, DelayVar)  -- Lerp hrp towards direction
	end
end)

This is because when the player is running backwards, the camera is facing, well, backwards. One method you could use is by using the dot product, which is explained well here. Basically, if you dot the LookVectors of the HumanoidRootPart and the Camera, you’ll get a number between -1 and 1 of how much they go in the same direction. We can assume that any value above 0 is in the same direction, and any value below 0 is not.

But what would I do with this information though?

I’m assuming you don’t want the character to face backwards when running backwards, so add in a check in the initial if statement to see if the character and camera are facing the same relative direction, and if not, don’t make the character start facing the camera’s direction.

local function SyncHeights(p0, p1)
	local Flat = Vector3.new(1, 0, 1)
	return p0 * Flat, p1 * Flat
end
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function(dt)
	local dotProduct = Camera.CFrame.LookVector:Dot(hrp.CFrame.LookVector);
	if RMBHeld() or LMBHeld() and dotProduct > -0.25 then
		local TargetPosition = Camera.CFrame.Position + (Camera.CFrame.LookVector * Client.CameraMaxZoomDistance * 2)
		local LookerFrame = CFrame.lookAt(SyncHeights(hrp.Position, TargetPosition))
		local Frame = LookerFrame - LookerFrame.Position + hrp.Position
		
		hrp.CFrame = hrp.CFrame:lerp(Frame, DelayVar)  -- Lerp hrp towards direction
	end
end)

Are you sure that’s the problem though? If you took a look at the video posted in the op, the player is still being lerped in the direction of the camera.

I should mention, the DelayVar in hrp.CFrame = hrp.CFrame:lerp(Frame, DelayVar) is 0.2, when changed to DelayVar = 1, the player rotates towards the camera perfectly fine.
Obviously this isn’t ideal as there is no delay to the player rotation now.
https://gyazo.com/dc0393b474df448954a1214b8b54f497

I’ve misunderstood in that case. Your issue is that the delay wasn’t fast enough. Try higher values.

The problem is, I want to keep some delay when the player rotates their camera, similar to camera systems you can find in Mount and Blade or Bleeding Blades. However, higher values remove this delay in rotation.

Jesus Christ, all I had to do was disable AutoRotate