How to make the camera follow the moving part

So I have this blue part as the character for a test game, and I’ve made it work with wasd for movement. but I’m trying to make it so that the camera will follow the part and not be able to be moved by the player. sort of like in a 2d game.

It would look like this as you are moving around:

I tried setting the camera subject to the part, but i could still move the camera. Is there a way I can have it fixed at this angle while the player moves?

You could set the cameratype to scriptable and update the cframe through a renderstepped event.

Below is a LocalScript I made that makes the camera follow the player at a desired distance and pitch + yaw angle. This code example is for a normal humanoid player, but all you need to do is change the character and characterRoot variables for the camera to follow any part instead. I placed this script inside StarterCharacterScripts

local player = game:GetService("Players").LocalPlayer

--modify these
local character = script.Parent --change to whatever the character model is
local characterRoot = character:WaitForChild("HumanoidRootPart") --change to root character part
local desiredPitch = 45 --45 degree pitch
local desiredYaw = 45 --45 degree yaw
local desiredCameraDistance = 15 --15 studs away

local camera = workspace.CurrentCamera
camera.Changed:Wait()
camera.CameraType = Enum.CameraType.Scriptable
local desiredCameraAngle = CFrame.fromOrientation(-math.rad(desiredPitch), math.rad(desiredYaw), 0)

game:GetService("RunService"):BindToRenderStep("CameraFollow", Enum.RenderPriority.Camera.Value+1, function()
	local characterCf = characterRoot.CFrame
	local newAngleCf = CFrame.new(characterCf.Position) * desiredCameraAngle
	camera.CFrame = newAngleCf - (desiredCameraDistance * newAngleCf.LookVector)
end)
6 Likes