Rotating Player CFrame on shiftlock in a custom camera SOMETIMES not working correctly

Im making a custom camera script, the only thing i can’t figure out how to do is to make the player rotate while in shift lock. Sometimes it will work correctly, the player will only look forward relative to the camera, but most times it will rotate the player weirdly. The rest is fine,

while RunService.RenderStepped:Wait() do
	local dt = tick() - pastTick
	if humanoid.MoveDirection.Magnitude > 0 and humanoid.WalkSpeed > 0 then
		local target
		if shiftLock then 
			target = (hrp.CFrame + Vector3.new(camera.CFrame.LookVector.X, hrp.CFrame.Position, camera.CFrame.LookVector.Z)).Position --This is not working
		else
			target = (hrp.CFrame + humanoid.MoveDirection.Unit).Position --Working fine
		end
		hrp.CFrame = hrp.CFrame:Lerp(CFrame.lookAt(hrp.CFrame.Position, target), dt * deltaTimeScale)
		
		local MoveDirection = hrp.CFrame:VectorToObjectSpace(humanoid.MoveDirection)
		Tilt = Tilt:Lerp(CFrame.Angles(math.rad(-MoveDirection.Z) * MaxTiltAngle, math.rad(-MoveDirection.X) * MaxTiltAngle, 0), dt * deltaTimeScale)
	elseif humanoid.MoveDirection.Magnitude == 0 then
		Tilt = Tilt:Lerp(CFrame.new(), dt * deltaTimeScale)
	end
	RootJoint.C0 = RootC0 * Tilt
        --[rest of the camera logic]
        pastTick = tick()
end

Working:


Not Working:

1 Like

Shouldn’t hrp.CFrame.Position be something like hrp.CFrame.Position.Y?

You’re currently passing a Vector3 into the Y position of Vector3.new(x, y, z), but it expects a number. This is likely breaking the calculation. Maybe try changing that?

1 Like

Working 100%. I feel dumb, but also confused about why it was working only sometimes

1 Like

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