How can I make a camera look at a part

I am making a alarm system where instead of using buttons, I want to make the players camera to switch to a part near a monitor of where then a surface GUI will be displayed which is not hard, but the problem I am trying to solve is how can I make a camera look where I want rather than have its subjects switched but still remain in the same position/looking angle before the script sets it to scriptable type camera.

You can use:

Camera.CFrame = CFrame.new(Camera.Position, Part.Position)
5 Likes

Set the CameraType to Scriptable and then set the CFrame of the Camera to the part.

2 Likes

Ah. I see what you’re trying to do…

For a game I’m working on, I also have such a system. The way I do it is that I position an Attachment object some ways outside of the screen and set the camera CFrame to that. This means we can keep the same monitor model without an extra part just for Camera CFraming.

In order to make revert the camera, we have an InputEnded event on the SurfaceGui’s container. When the mouse leaves the general Gui area, we reset the camera CFrame back to the player’s character. Of course, in the case of unexpected incidents that make the user unable to use a terminal (e.g. dying), we also have to reset the camera then.

2 Likes

Depends on the context, for a Aim Assist I wouldn’t say it’s required.
He can just use RunService.RenderStepped().

local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local AimingAtPart:BasePart = nil -- change it to the part you're aiming at?

RunService.RenderStepped:Connect(function()
	if AimingAtPart then
		local newCFrame = CFrame.new(Camera.CFrame.Position, AimingAtPart.Position)
		Camera.CFrame = Camera.CFrame:Lerp(newCFrame, .05)
	end
end)

Edit: That’s a LocalScript btw.

https://gyazo.com/68ccae102dbcd1d892d17639eb401742