I’m making a first-person camera script. It’s primitive right now, so don’t tell me to add anything or massively change my code. The issue is that whenever I look at something (player:GetMouse().Target is nil), the camera drifts up towards the horizon (player:GetMouse().Hit.Position moves away from the camera in the direction of the camera). I have tried to isolate the problem but have been unsuccessful. Thanks.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local HEIGHT_OFFSET = 0
local function updateCamera()
print(player:GetMouse().Target)
print(player:GetMouse().Hit.Position)
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local character = player.Character
if character then
local root = character:FindFirstChild("Head")
if root then
local rootPosition = root.Position + Vector3.new(0, HEIGHT_OFFSET, 0)
local cameraPosition = rootPosition
if player:GetMouse().Target == nil or player:GetMouse().Target.Parent~=character then camera.CFrame = CFrame.lookAt(rootPosition, player:GetMouse().Hit.Position) end --problem area
end
end
end
RunService:BindToRenderStep("FPCam", Enum.RenderPriority.Camera.Value + 1, updateCamera)
EDIT: I’ve done some further testing and have discovered that the camera always drifts up, never down, and that it drifts up very slightly still even when looking at the skybox.