Problem with orientation when using CFrame and Vector3 with camera

Hello!

I am currently writing a script that teleports your camera to a location when you click on a part.

To accomplish this, I am using Vector3 and CFrame to manipulate the camera’s position and orientation.

The position part of the script works completely fine, however the orientation part of the script sets it at a weird angle, even though the orientation Vector3 is set to (0, 0, 0).


Here is my code:

local re = game.Workspace.ClickPart.ClickDetector.Script.RemoteEvent

re.OnClientEvent:Connect(function()
	print("Signal received.")
	local camera = game.Workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Scriptable
	
	local position = Vector3.new(-1533.95, 0.5, 783.06)
	local orientation = Vector3.new(0, 0, 0)
	local cameraCFrame = CFrame.new(position, orientation)
	workspace.CurrentCamera.CFrame = cameraCFrame
end)

Here are also some pictures for reference:

Above: What is happening.

Above: What it’s supposed to look like.


I have tried looking everywhere, but I can’t find a good solution.

Can someone help me? Thanks!

1 Like

CFrame.new takes two parameters, position and lookAt, which are both Vector3s.
Where you’re getting confused is that the second one, lookAt, describes a position that the camera will look towards, not the actual orientation of the camera.
Basically you’re telling the camera to go far away and look at the origin of the world, (0,0,0).
Some possible solutions:

  • A. Remove the “orientation” portion from the CFrame.new call, since you’re trying to have it be 0,0,0 anyway
  • B. Instead of using CFrame.new(position,orientation), you can try something like CFrame.new(position) * CFrame.Angles(0,0,0)
  • C. Setting orientation to the yellow part’s position instead
2 Likes

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