Welding the Camera to a part

Ok, so. I’ve been getting started on making a Custom Character Controller, since I feel the default Roblox one lacks on some points. Already have I run into a problem, when spawning in a model, which I use as a placeholder character at the moment, I change the client’s Camera Subject to be the model, and change the Camera Type to Custom. But here’s my issue, when I do just that, the player can freely rotate the Camera in just like normal, what I would want, is that the camera is locked facing the same direction as the part, I achieved this by changing the Camera Type to Fixed, but then another problem occurs, the Camera is left behind whenever the character moves, I can only imagine, that if I constantly move the Camera’s CFrame, it will look horrible. This is my current Code:

local CurrentCamera = game:GetService('Workspace').CurrentCamera
CurrentCamera.CameraSubject = Target
CurrentCamera.CameraType = Enum.CameraType.Custom

Any help is appreciated!

3 Likes

Set the CameraType to Scriptable and then constantly set the CFrame within a RenderStep loop:

local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
game:GetService("RunService"):BindToRenderStep("MyCamera", Enum.RenderPriority.Camera.Value, function()
   cam.CFrame = target.CFrame
end)

A couple notes:

  • If you run this code immediately at runtime startup, the core scripts might override your CameraType setting. So you might have to delay a bit first.
  • This will make the camera very static. A lot of users don’t like the camera being completely locked like this.
  • Coding a custom camera is a lot of work, but can be very rewarding if done correctly!
10 Likes

Thanks a lot!
It works perfectly, I don’t have to worry about the core scripts overwriting the camera properties as I have a server sided script spawn the character in late already.

I am also aware that coding a custom camera requires a lot of work and dedication, which is why I want to do it!

Once again, that you for your suggestion, it really helped, I’ve never really looked much into RenderStepped, that’s a mistake on my part.

2 Likes

I’m not sure if this is just a problem for me or not, but when I use RunService for my main menu camera, it lags my mouse cursor.

1 Like

This thread is 4 years old, please make a new thread instead.

1 Like