Camera script dispalying camera sideways

--Get service needed for events used in this script
local RunService = game:GetService("RunService")	

-- Variables for the camera and player
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
-- Constant variable used to set the camera’s offset from the player
local CAMERA_OFFSET = player.Character:WaitForChild("CameraOffset").Value

camera.CameraType = Enum.CameraType.Scriptable
print(camera.CameraType)
local debounce = false
local function onRenderStep()

	if debounce == false then
		debounce = true

		if player.Character then
			if camera.CameraType == Enum.CameraType.Scriptable then
				print("e")
				local CAMERA_OFFSET = player.Character:WaitForChild("CameraOffset").Value
				local playerPosition = player.Character.Torso.Position
				local cameraPosition = playerPosition + CAMERA_OFFSET

				-- make the camera follow the player
				camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)

			end
		end
		debounce = false
	end
end
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onRenderStep)

The result:


The camera faces left to right, instead of back to front like I want it to, how can I do that?

1 Like

It looks like you are adding a number to a vector3, is CameraOffset a vector3 or just a number?

It’s a vector3.
Also, I am trying to use CFrame.Frommatrix to make it look in the right direction but I can’t figure out the right combination of numbers, I was trying making the right side point to 0,0,1 which is the right, and the top side point to -1,0,0 which is forward so it should look straight down back to front.

				camera.CFrame = CFrame.fromMatrix(
					cameraPosition,
					Vector3.new(0,0,1),
					Vector3.new(1,0,0)
				)

This causes the camera to look exactly like the picture

			camera.CFrame = CFrame.fromMatrix(
				cameraPosition,
				Vector3.new(1,0,0),
				Vector3.new(0,0,-1)
			)
		end

welp guess it wasn’t that hard lol.

Try setting the CameraOffset’s Z to 10, and change your camera CFrame setter to use lookAt, its faster more accurate than CFrame.new(v1,v2).

camera.CFrame = CFrame.lookAt(cameraPosition, playerPosition)
1 Like