I have a system where I can lock my camera onto enemies:
-- Local script
RS.RenderStepped:Connect(function()
if CameraLockToggle == true then
if CameraTarget then -- CameraTarget is chosen in another function
local lookAtPosition = CameraTarget.HumanoidRootPart.Position
Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, lookAtPosition)
end
end
end)
The issue is that when the camera is locked, it allows 0 freedom for any additional manual camera movement from the player.
As you can see, whenever I try to move my camera, it snaps back to its original spot. What I’m looking for is how to add some leeway to the camera, while it still faces towards the target.
This would allow for prediction aiming, increased viewing range, and an overall smoother camera experience for the player.
You can lerp the camera’s CFrame to the goal CFrame.
Code:
-- Local script
RS.PreRender:Connect(function(deltaTime)
if CameraLockToggle == true and CameraTarget then
local lookAtPosition = CameraTarget.HumanoidRootPart.Position
Camera.CFrame = Camera.CFrame:Lerp(CFrame.lookAt(Camera.CFrame.Position, lookAtPosition), deltaTime / 10)
end
end)
The higher the divisor is the higher the time it will take for the camera to snap on.
Sorry for asking, but could you send a video of how it looks? I just realized I might want to implement a similar camera in my game, but I’m not sure if it’s what I want yet.