Issue with camera and bodyturning

I am currently trying to make an OTS system, and I want to make it so the camera lerps with

			local CameraLerp = Camera.CFrame:Lerp(CFrame.new((Character.PrimaryPart.Position - Offset)), 0.025)

with the entire code block being,

RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter


			local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
			
			local BodyLerp = Character.PrimaryPart.CFrame:Lerp(CFrame.new(Character.PrimaryPart.Position) * CFrame.Angles(0,y,0), 0.025)
			local CameraLerp = Camera.CFrame:Lerp(CFrame.new((Character.PrimaryPart.Position - Offset)), 0.025)
			
			Character.PrimaryPart.CFrame = BodyLerp
			Camera.CFrame = CameraLerp
		end) 

The video attached shows the issue itself

My problem is… How could I make it so the player can still move their camera around freely, with the lerp, but also without forcing the player a certain direction to look?

1 Like

It faces one direction because you’re lerping the CFrame to the character’s position converted into CFrame – because a Vector3 is considered as the positional component (not the rotational component).

Meaning, it will always face the direction of (0, 0, -1), proof:

warn(CFrame.new(Character.PrimaryPart.Position).LookVector) -- (-0. -0, -1)

Instead, you can apply the offset as a CFrame on the camera’s CFrame itself:

RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter


	local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()

	local BodyLerp = Character.PrimaryPart.CFrame:Lerp(CFrame.new(Character.PrimaryPart.Position) * CFrame.Angles(0,y,0), 0.025)
	-- i cframe'd ur vector but i recommend just actually making ur offset a cframe
	local CameraLerp = Camera.CFrame:Lerp(Camera.CFrame * CFrame.new(Offset)), 0.025)

	Character.PrimaryPart.CFrame = BodyLerp
	Camera.CFrame = CameraLerp
end)
1 Like

you are an absolutely amazing lifesaver, I knew that vector3 was a positional component but I never really knew how to apply it outside of using vector3s, amazing, Thank u.

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