Scripting a player's Camera

Hey, my problem is I want to make a camera look at an object in a frozen position that can’t be changed by the player… I want it to stay there 24-7 and not be focused on the player, as what I am trying to do it a simulation. How would I do this?

1 Like

Use Camera.CameraType. This allows you to control how the camera functions. If you set the type to Scriptable, the player will not be able to move the camera and you (as the name implies) can script it.

Then it’s as simple as setting the camera’s CFrame property to be the correct orientation and location.

3 Likes

Okay, that makes sense, but how would I set it to face the model? In case you’re wondering what simulation I’m trying to make that might give a clue to how you could help me here is a photo of the build so far…

11 Likes

CFrames has two properties, Position and LookVector. Position is obvious, but look vector is the position you want the CFrame to look at (as explained in This post. It talks about a part facing the camera but it can be easily switched.)
You can simply set the Camera’s CFrame to have the Position you want, then the LookVector set to a part’s Position property.

1 Like

Im trying this out as well as a tutorial video on youtube, but I seem to be getting lost.

1 Like

Simplest way you could do this is CameraInterpolation

Which is where you have two parts, basically a camera position, and a camera focus.

Then in a local script you can do something like this:

local Camera = workspace.CurrentCamera
Camera.CameraType = "Scriptable"
Camera:Interpolate(CameraPosition.CFrame, CameraFocus.CFrame, 3)
1 Like

What is the parent of the local script as when I put in in starter player scripts it didn’t work…

1 Like

I will send you a template place you can use.

CameraInterpolation.rbxl (17.8 KB)

2 Likes

Thank you so much! I am trying it out!

1 Like

I have to go so I will try it out and let you know about it when I get back home okay.

1 Like

Alright, remember that this works with multiple parts as well, as long as you define them in the interpolation.

Okay, I’m home and testing it.

Thanks so much! It’s working well!

There is another script I would like to ask assistance with before I end this thing.

How would I make the game delete the roblox character so it’s not see in the simulation “making the player invisible.”

Set Players.CharacterAutoLoads to false, this will cause the player to not automatically load into the game.

1 Like

That just made the camera scripts break.

What I mean is to make the player’s character be invisible for allow their camera and scripts to load in still.

Delete the character once it loads into the game?

Otherwise you can just place it into a box off of the screen or something and disable movement etc.

What I want to do is I want the character to still be there, but be invisible as turning the transparency up to 1.0 and deleting the face.

It’s like taking the whole character and moving it under lighting or Server Storage.

And I just did it… Wow. Final set of code from both scripts…

Script 1 [Camera]:

local Player = game.Players.LocalPlayer

repeat wait() until Player.Character

local Camera = workspace.CurrentCamera

Camera.CameraType = "Scriptable"

Camera:Interpolate(workspace.Position.Part.CFrame, workspace.Foucs.Part.CFrame, 3)

Script 2 [Invisible Character]:

game.Workspace.ChildAdded:connect(function(character)
 if game.Players:GetPlayerFromCharacter(character) then
  	character:WaitForChild("ForceField"):Destroy()
	character.Parent = game.ServerStorage 
 end  
end)
1 Like