Setting Camera CFrame kills character

Hello!

Recently I’ve tried to play my RDC 2018 gamejam game and ran into weird issue. I couldn’t get my character to spawn. I’ve tried creating SpawnLocation, but that didn’t fix the issue either. After some debugging I’ve figured out it’s an issue with setting Camera CFrame.

The issue is related to CFrame.new ( Vector3 pos, Vector3 lookAt ) constructor.

Setting camera’s CFrame to

CFrame.new(Vector3.new(), Vector3.new(0, -1, 0))

will work correctly, but if we change -1 to -110 or -109 (haven’t found any other numbers causing that issue, -111 and -108 work fine), it will start killing character on change.

Full script:

local Camera = game:GetService("Workspace").CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable

local RunService = game:GetService("RunService")
while RunService.RenderStepped:wait() do
	-- Those work correctly:
	-- Camera.CFrame = CFrame.new(Vector3.new(), Vector3.new(0, -1, 0))
	-- Camera.CFrame = CFrame.new(Vector3.new(), Vector3.new(0, -111, 0))
	
	-- This does not work correctly:
	-- Camera.CFrame = CFrame.new(Vector3.new(), Vector3.new(0, -109, 0))
	Camera.CFrame = CFrame.new(Vector3.new(), Vector3.new(0, -110, 0))
end

(Place in StarterPlayerScripts, the magnitude matters, if we move both start and end position, the issue will still be happening)

I honestly have no idea why it could happen especially since CFrame.new(Vector3.new(), Vector3.new(0, -110, 0)) should be the same as CFrame.new(Vector3.new(), Vector3.new(0, -1, 0)) . This seems to be a really complex issue - pretty easy to fix, but might have more serious root cause.

https://gyazo.com/6f73d268f23d8ef329239fb9996efc88 (Working fine - not killing)
https://gyazo.com/d388fbf9ee8e751922450d5872ed6dda (Working incorrecetly - killing)

For sure the bug started happening after RDC 2018.

4 Likes

That’s really weird. I saw a post recently about this and adding a spawn location seemed to fix the issue.

That’s unrelated - It happens even after I’ve made SpawnLocation (Already seen this topic thus noted that already in the post).

Fixed the gif links, apparently I’ve included one link twice.

This issue can happen when not using this constructor; I was able to repro this issue when setting the camera’s CFrame to CFrame.new(0, 0, 0, -0, 0.99999994, -0, -0, 0, 0.99999994, 1, 0, -0), the result of CFrame.new(Vector3.new(), Vector3.new(0, -110, 0)). When the 0.99999994 are replaced with 1 it works fine.

I don’t think the result of CFrame.new(Vector3.new(), Vector3.new(0, -110, 0)) should even be CFrame.new(0, 0, 0, -0, 0.99999994, -0, -0, 0, 0.99999994, 1, 0, -0) . Seems like two issues at one place.

Floating point inaccuracies make it impossible to make this answer exact. The actual issue looks like it picks up on the minute difference and kills the character because of it.
Another example of floating point inaccuracies with CFrames

print(CFrame.Angles(math.pi,0,0)) --> 0, 0, 0, 1, 0, 0, 0, -1, 8.74227766e-08, 0, -8.74227766e-08, -1
1 Like

Thanks for the report! We’ve filed this internally and we’ll follow up here when we have an update for you.

2 Likes

I am in the process of checking over bug reports and following up on some bugs that haven’t received any activity in a while.
Is this issue still occurring or can you confirm that this bug has been resolved?

1 Like

The bug has not yet been resolved. It’s still happening.

Alright, thanks for the info. I appreciate it.

1 Like

Np. I’ve also realized that CFrame.new(pos, lookAt) constructor has been recently deprecated in favor of CFrame.lookAt(at, lookAt, up) constructor, thus letting know that the issue happens in the new version as well.

To reproduce

local Camera = game:GetService("Workspace").CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable

local RunService = game:GetService("RunService")
while RunService.RenderStepped:wait() do
	Camera.CFrame = CFrame.lookAt(Vector3.new(), Vector3.new(0, -110, 0))
end
1 Like

Bump. Have this weird issue with:

		local cam = workspace.CurrentCamera;
		local partPosition = part.Position;

		cam.CameraType = Enum.CameraType.Scriptable;
		cam.CFrame = CFrame.lookAt(
			Vector3.new(partPosition.X, 5, partPosition.Z), -- Cam pos
			partPosition -- Look at
		)

Video (Streamable.com)

2 Likes