Want camera to be offset from player while in a seat, but be able to be rotated with right click

I have a VehicleSeat on a platform that rotates.
While the player is seated I need the camera to be offset from the player, but be able to rotated as it normally does while holding mouse right click. The monitorCamera is an Attachment I’ve got in the VehicleSeat. The reason is that with a VehicleSeat normal operation the camera jumps outside the entire observatory model and you can scroll through items. It’s a small room, so I’d like the camera to be fixed to an open Position inside for better viewing, not just centered at the player head.

I’ve searched the forums but any of the camera types I’ve tried don’t allow the camera to be rotated at that offset.

I tried asking the Assistant and here’s the LocalScript in StarterCharacterScripts it gave me, which works but the camera stays pointed at the original Orientation of the Attachment.

Thanks for any help. (And yes, I’m going to tween the camera movement to the offset Position and back, but that’s easy to add after it works properly!)

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local seat = workspace.Observatory.Telescope["Telescope bracket"]:WaitForChild("VehicleSeat")
local monitorCamera = seat:WaitForChild("MonitorCamera")

local camera = workspace.CurrentCamera
local originalCameraPosition = camera.CFrame

local function onSeated(rigType, seatPart)
    if seatPart == seat then
		camera.CameraType = Enum.CameraType.Scriptable 

How can I allow the camera to rotate with RH mouse so the player can look around? Do I now have to make the Attachment rotate while holding the RH mouse button?

		while seat.Occupant do
			camera.CFrame = CFrame.new(monitorCamera.WorldCFrame.Position)
			task.wait()
		end
    end
end

local function onUnseated()
    camera.CameraType = Enum.CameraType.Custom
end

humanoid.Seated:Connect(onSeated)
humanoid.StateChanged:Connect(function(oldState, newState)
    if oldState == Enum.HumanoidStateType.Seated and newState ~= Enum.HumanoidStateType.Seated then
        onUnseated()
    end
end)
1 Like

Call the update function in the loop:

local UIS = game:GetService("UserInputService")
-- Camera Settings
local CAMERA_DISTANCE = 25 -- Distance from part in studs
local currentYaw = 0
local currentPitch = 0
local wasRightMouseDown = false
local offset = Vector3.new(0, 10, 0) 

function update(camera, part)
	camera.CameraType = Enum.CameraType.Scriptable
	local partPosition = part.CFrame.Position

	local isRightMouseDown = UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton2)

	if isRightMouseDown ~= wasRightMouseDown then
		UIS.MouseBehavior = isRightMouseDown and Enum.MouseBehavior.LockCurrentPosition or Enum.MouseBehavior.Default
		wasRightMouseDown = isRightMouseDown
	end

	if isRightMouseDown then
		local delta = UIS:GetMouseDelta()
		if delta.Magnitude > 0 then
			currentYaw = currentYaw - (delta.X * 0.1)
			currentPitch = math.clamp(currentPitch - (delta.Y * 0.1), -80, 80)
		end
	end

	local cameraRotation = CFrame.fromOrientation(math.rad(currentPitch), math.rad(currentYaw), 0)
	local cameraPos = partPosition + cameraRotation.LookVector * -CAMERA_DISTANCE
	camera.CFrame = CFrame.new(cameraPos, partPosition + offset)
end

Essentially what this does is use a pitch and yaw axis to let the player rotate the camera around the part that is being passed to the update function. If you want to offset the position the camera rotates around, you can change the offset vector.