My camera for whatever reason does not stick to the character’s head, despite using CFrame:lookAt()
the camera will not be attached to the head for a split second
somebody please help me out with this i hate camera scripting
video of what’s happening:
and the code (don’t worry about the length of it, all of the functions serve the same purpose!!!):
local tService = game:GetService("TweenService")
local tweenParameters = TweenInfo.new(
0.15,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out
)
local scalingFactor = 0.05
local cameraFunctions = {
FirstComboSwing = function(camera: Camera, char: Model)
local head = char:FindFirstChild("Head")
local originalCFrame = camera.CFrame
local targetLookAtPosition = head.Position + Vector3.new(-10, -0.5, 0) * scalingFactor
local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)
camera.CFrame = targetCFrame
local shiftCameraBack = tService:Create(camera, tweenParameters, {CFrame = originalCFrame})
shiftCameraBack:Play()
end,
SecondComboSwing = function(camera: Camera, char: Model)
local head = char:FindFirstChild("Head")
local originalCFrame = camera.CFrame
local targetLookAtPosition = head.Position + Vector3.new(5, 0.5, 0) * scalingFactor
local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)
camera.CFrame = targetCFrame
local shiftCameraBack = tService:Create(camera, tweenParameters, {CFrame = originalCFrame})
shiftCameraBack:Play()
end,
ThirdComboSwing = function(camera: Camera, char: Model)
local head = char:FindFirstChild("Head")
local originalCFrame = camera.CFrame
local targetLookAtPosition = head.Position + Vector3.new(-10, -0.5, 0) * scalingFactor
local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)
camera.CFrame = targetCFrame
local shiftCameraBack = tService:Create(camera, tweenParameters, {CFrame = originalCFrame})
shiftCameraBack:Play()
end,
HeavySwing = function(camera: Camera, char: Model)
local head = char:FindFirstChild("Head")
local originalCFrame = camera.CFrame
local targetLookAtPosition = head.Position + Vector3.new(0.5, -0.5, 0) * scalingFactor
local targetCFrame = CFrame.lookAt(camera.CFrame.Position, targetLookAtPosition)
camera.CFrame = targetCFrame
local shiftCameraBack = tService:Create(camera, tweenParameters, {CFrame = originalCFrame})
shiftCameraBack:Play()
end,
}
local cameraManipulationModule = {}
function cameraManipulationModule.Manipulate(camera: Camera, manipulationType: string, char: Model)
cameraFunctions[manipulationType](camera, char)
end
return cameraManipulationModule