How would i be able to make my camera follow the rotation of a part

How would i be able to make my camera follow the rotation of a part?

1 Like

What exactly are you going for?
A. Are you trying to mirror that part’s rotation onto your camera?
B. Use that part as a camera?

If A, then you could probably do something like this:

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

local Part = (...) --Path to wherever your part is

function ApplyPartRotationToCamera()
    local X, Y, Z = Part.CFrame:ToEulerAngles() -- get the part's rotation
    local CameraPos =  CFrame.new(Camera.CFrame.Position) --camera's position with no rotation matrix applied
    Camera.CFrame = CameraPos * CFrame.FromEulerAngles(X,Y,Z) --apply the part's rotation onto the camera's position
end)

RunService:BindToRenderStep("PartRotation", Enum.RenderPriority.Character.Value, ApplyPartRotationToCamera) --make sure this runs AFTER camera

Note that this will make it impossible to move the camera normally and you’ll have to add your own behavior to it.

If B, you can just set the CameraSubject to the part iirc. There should be a property for it.

You could also do something like that if it is local for one player:

local cam = workspace.CurrentCamera
cam.CameraSubject = PartToFollow
cam.CameraType = Enum.CameraType.Attach

and then set back the current camera to the last properties after a certain amount of time

i tried running this ingame and got this

  23:00:12.118  RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: Workspace.aeroactual.Test:12: attempt to call a nil value  -  Studio
  23:00:12.136  Workspace.aeroactual.Test:12: attempt to call a nil value  -  Client - Test:12

hello, i need an example of how to make a player’s camera move to a Part or Attachment’s location in the workspace