Character killed upon changing camera cframe (Cframe.lookat)

Hello, I ran into a really weird issue today when trying to change the camera position while changing the lookvector (i think its look vector at least or rotation, what ever)

this is how it looks:
RobloxStudioBeta_gommBmgyqd

I have no idea what this could be, like nowhere close to an idea. But when commenting out the line that changes the lookvector it doesn’t kill me

Here’s the code snippet:

function Update(dt: number)
	-- get_debug_data just returns a number so that isn't the problem!
	local camera_height = get_debug_data() or camera_height
	local camera_position = humanoidRootPart.Position + Vector3.new(0, camera_height, 0)
	
	camera.CFrame = CFrame.new(camera_position)
	
	-- the line bellow kills me ... somehow?
	camera.CFrame = CFrame.lookAt(camera.CFrame.Position, humanoidRootPart.Position, Vector3.yAxis)
end

Is this a bug or am i just stupid?

1 Like

Tried this out myself too and got same result.
This shouldn’t be happening lol, submit a bug report I guess

well atleast I know that it’s not just on my end then. I guess ill try to submit a bug report but it seem kinda tedius :cry:

Can you please provide a repo file? I tried replicating your issue but can’t get the player to die

Found a bug report from a couple years old. Testing their reproduction steps seems to still cause the issue to occur, and the print statements I added are consistant between testing your provided code and the bug reproduction

1 Like

Based on the replies in the bug report, it seems a workaround is to try and round the values in the CFrame. Apparently it’s to do with a floating point issue causing a mismatch, which the game doesn’t know how to process so it just kills the player xD

Code used to test
local camera_height = 0
local res:CFrame = 0
local HRP = nil
local camera = workspace.CurrentCamera

local function CharacterAdded(char)
	char.Humanoid.Died:Connect(function()
		print(camera_height)
		warn(res)
		conn:Disconnect()
	end)
	HRP = char.HumanoidRootPart
end

game.Players.LocalPlayer.CharacterAdded:Connect(CharacterAdded)
if game.Players.LocalPlayer.Character then CharacterAdded(game.Players.LocalPlayer.Character) end

while not HRP do task.wait() end

local function RoundVector(Vector: Vector3, Precision: number)
	return Vector3.new(
		math.round(Vector.X*Precision)/Precision,
		math.round(Vector.Y*Precision)/Precision,
		math.round(Vector.Z*Precision)/Precision
	)
end

function Update(dt: number)
	res = CFrame.new(Vector3.new(), Vector3.new(0, -110, 0))
	
	local XVector = RoundVector(res.XVector, 1000)
	local YVector = RoundVector(res.YVector, 1000)
	local ZVector = RoundVector(res.ZVector, 1000)
	
	res = CFrame.fromMatrix(Vector3.new(), XVector, YVector, ZVector)
	workspace.CurrentCamera.CFrame = res
end

conn = game["Run Service"].Stepped:Connect(Update)

Updated code for you to use
local function RoundVector(Vector: Vector3, Precision: number)
	return Vector3.new(
		math.round(Vector.X*Precision)/Precision,
		math.round(Vector.Y*Precision)/Precision,
		math.round(Vector.Z*Precision)/Precision
	)
end

function Update(dt: number)
	-- get_debug_data just returns a number so that isn't the problem!
	local camera_height = get_debug_data() or camera_height
	local camera_position = humanoidRootPart.Position + Vector3.new(0, camera_height, 0)

	local new_cframe = CFrame.lookAt(camera_position, humanoidRootPart.Position, Vector3.yAxis)

	local XVector = RoundVector(new_cframe.XVector, 1000)
	local YVector = RoundVector(new_cframe.YVector, 1000)
	local ZVector = RoundVector(new_cframe.ZVector, 1000)

	camera.CFrame = CFrame.fromMatrix(camera_position, XVector, YVector, ZVector)
end
1 Like

Bumped the bug report.

Camera position definitely shouldn’t mess with character health. :thinking:

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