Camera.lookAt increases when moving?

i hate camera manipulation

i’ll just include a video of what happens


and this is the code;

local rService = game:GetService("RunService")

local scalingFactor = 0.01

local cameraFunctions = {
	FirstComboSwing = function(camera: Camera, char: Model)
		local head = char:FindFirstChild("Head")
		local originalCFrame = camera.CFrame
		
		local relativeOffset = Vector3.new(-3, -0.5, 0)
		local targetLookAtPosition = head.CFrame:PointToWorldSpace(relativeOffset * scalingFactor)

		local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)

		camera.CFrame = targetCFrame				
	end,

	SecondComboSwing = function(camera: Camera, char: Model)
		local head = char:FindFirstChild("Head")
		local originalCFrame = camera.CFrame
		
		local relativeOffset = Vector3.new(3,0.5,0)
		local targetLookAtPosition = head.CFrame:PointToWorldSpace(relativeOffset * scalingFactor)

		local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)

		camera.CFrame = targetCFrame		
	end,

	ThirdComboSwing = function(camera: Camera, char: Model)
		local head = char:FindFirstChild("Head")
		local originalCFrame = camera.CFrame
		
		local relativeOffset = Vector3.new(-3, -0.5, 0)
		local targetLookAtPosition = head.CFrame:PointToWorldSpace(relativeOffset * scalingFactor)

		local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)

		camera.CFrame = targetCFrame		
	end,

	HeavySwing = function(camera: Camera, char: Model)
		local head = char:FindFirstChild("Head")
		local originalCFrame = camera.CFrame
		
		local relativeOffset = Vector3.new(0.5, -0.5, 0)
		local targetLookAtPosition = head.CFrame:PointToWorldSpace(relativeOffset * scalingFactor)

		local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)

		camera.CFrame = targetCFrame		
	end,
}

local cameraManipulationModule = {}

function cameraManipulationModule.Manipulate(camera: Camera, manipulationType: string, char: Model)
	cameraFunctions[manipulationType](camera, char)
end

return cameraManipulationModule

Obvious issue is that your adding vector3 to look vector and not putting it back to “normal”

im not sure if this 100% works but you could try multiplying the camera’s CFrame by the rotation with CFrame.Angles rather than using CFrame.lookAt so that it doesnt conflict with anything else

i used to set it back to “normal” (i assume you’re referring to the originalCFrame variable), but i stepped away from that idea (and forgot to get rid of that variable)

huh? you mean something like;

camera.CFrame = camera.CFrame * CFrame.Angles(x,y,z)

:question:

yea like that, also make sure to use math.rad(x) and so on if youre using degrees for x y and z

oh my goodness.

it WORKS

you are the goat of camera manipulation and i thank you for enlightening my code and my camera manipulation knowledge :pray:

2 Likes

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