Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to keep the Camera from panning/zooming in and out?

So I'm making a custom character creator where the camera is focused in on the dummy, and the creator chooses what he wants to look like. I get the camera to focus on the dummy correctly; however, I don't know how to keep the player from zooming in and out. Here's what it looks like https://gyazo.com/3659eda39e6eaf138f3eba4a5445789f

This is my script so far:

local Player = game.Players.LocalPlayer
game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Player5.HumanoidRootPart
game.Workspace.CurrentCamera.Focus = CFrame.new(5,5,5)
game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(5,5,5)
game.Workspace.Camera.CameraType = "Watch"
game.Workspace.Camera.CFrame = CFrame.new(-250.85,181.476,2770)

Any suggestions? I have this script in a local script etc requirements met.

2 answers

✓ Accepted answer

There are three main methods that I use to keep the camera from zooming in/out.

(1.) (requires 0 scripting), you can change the properties CameraMaxZoomDistance and CameraMinZoomDistance inside StarterPlayer to the same value. (i.e. if you wanted a player's camera to only be able to stay 5 studs away you would change both values to 5)

(2.) (requires some scripting in a local script), This method will basically fix the camera to remain at a certain point in 3d space. Lets say I wanted the camera to always remain at point (0, 10, 0):

local wte = wait;
local new_cfr = CFrame.new;
local cam = game.Workspace.CurrentCamera;
spawn(function()
	while wte() do
		cam.CoordinateFrame = new_cfr(0, 10, 0);
	end
end)

(3.) (requires a lot of scripting in a local script) This method essentially 're-programs' the client camera to remain at a certain distance from the player according to their 'orientation'. You will have to override the standard CameraScript to get this method to completely work. You can do so by inserting a local script into StarterPlayer->StarterPlayerScripts and naming it CameraScript. Now Here is a basic example of code that will manage your client camera to remain a certain amount of studs away from your player and continuously face where your place is facing:

local wte = wait;
local new_cfr = CFrame.new;
local cam = game.Workspace.CurrentCamera;
local rot = CFrame.fromEulerAnglesXYZ;
local pcl = pcall;
local plrs = game:GetService("Players");
spawn(function()
	while wte() do
		pcl(function() --wrap the core block in a pcall in case the player's character died.
			local char = plrs.LocalPlayer.Character;
			local trs = char.Torso;
			cam.CoordinateFrame = trs.CFrame - (trs.CFrame.lookVector * 5) +
				(trs.CFrame.upVector * 5);
			cam.CoordinateFrame = cam.CoordinateFrame * rot(-0.15, 0, 0); --feel free to change these three values to rotate the camera however you wish.
			cam.CoordinateFrame.lookVector = trs.CFrame.lookVector;
		end);
	end
end);

Let me know which one you tried, and also feel free to let me know if you did get any errors because I just types all of this off of the top of my head, since I am always really busy.

I hope this helped.

Ok so this may not be the best way but the way I would do it is in the Player there are two properties called CameraMaxZoomDistance and CameraMinZoomDistance. If you wanted to lock it so the camera is zoomed out by ten I would set the min and the max to ten. For example. But of course you would do it with a script not by hand like I did.

2 comments

0

This helped too thank you.

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.