The title is probably a bit confusing, but I would like to know how to attach a camera’s position to a part but have your camera be rotatable like usual. An example of my definition of ‘rotatable’ is when you rotate your camera around your character by holding RMB. I want it to do exactly that, except fixes the camera position to a part I choose.
You can adjust the various properties of the CurrentCamera
in the Workspace
via a LocalScript
in order to achieve this.
Example
local CurrentCamera = workspace.CurrentCamera
local partToTrack = workspace.NameOfPart
CurrentCamera.CameraSubject = partToTrack
CurrentCamera.CameraType = Enum.CameraType.Track
--[[
These properties can be changed inside of a function so you can control
when it'll be changed to a designated part and back to the player's Character
--]]
--------------------------------------------------------
--[[
The following two properties do not need to be set manually when using
a CameraType that is not "Scriptable" -- I'm just showing it as an example
--]]
CurrentCamera.Focus = partToTrack.CFrame
CurrentCamera.CFrame = partToTrack.CFrame
Brief Explanation
The CameraSubject
will be the object that the camera will follow.
A CameraType
of Track
will allow for the player’s Camera to be locked onto that part, except they will have the ability to move their camera around as described in the OP.
The Focus
and CFrame
of the Camera do not need to be set under these circumstances, as the default camera scripts are being used and the CameraType
is not set to Scriptable
.
In order to bring the camera back to the player’s Character, ensure that the CameraSubject
is swapped back to the Humanoid
of the player’s Character, the CameraType
to Custom
, and the CFrame
property to the CFrame
of the Character’s Head (if I recall correctly).
Additional info/documentation on these properties can be found from the following Developer Hub pages:
Developer Hub Resources
In a LocalScript:
workspace.Camera.CameraSubject = Part
Change Part to the base of the place you want to focus on.