How to force zoom the camera?

How can I force the camera zoom? I mean, when I do something, I want the zoom to change as if you had changed it at will.

This code should move the camera forward. I think this is what you want.

local cam = workspace.CurrentCamera
local camCf = cam.CFrame
cam.CFrame = camCf+camCf.LookVector*15 -- change this number to what you want
2 Likes

You can’t access the zoom distance as if they were scrolling. As you can see in Camera | Roblox Creator Documentation it’s locked to roblox core script security. This means only roblox can use it. You’d have to use another method such as positioning the cframe, which the above comment shows how you could achive this.

You will have to loop through the CameraMaxZoomDistance and the CameraMinZoomDistance properties of Player to manually zoom in/out.

2 Likes

I just tested looping CameraMaxZoomDistance and the CameraMinZoomDistance and it doesnt work. I believe this is impossible.

I also tried script like this for the idea of setting the cframe:

            local char = game.Players.LocalPlayer.Character
			local cam = game.Workspace.CurrentCamera
			local zoomYoffset = 5
			local zoomVectorMult = 5
			local target = char.Head

			cam.CameraType = Enum.CameraType.Scriptable
			local p =CFrame.new(target.Position.x,target.Position.y+zoomYoffset/2,target.position.z) * -target.CFrame.LookVector*zoomVectorMult
			cam.CFrame = CFrame.new(p.x,p.y,p.z)
			wait()
			cam.CameraType = Enum.CameraType.Custom
			cam.CameraSubject = char.Humanoid

and that didnt work. To this day I still cant find a answer, I believe the actual solution is to try not build your game requiring setting the camera’s zoom for any people on this forum looking for an answer.

This works, set the CameraMaxZoomDistance the same as CameraMinZoomDistance and itll automatically force the camera to zoom to that distance.

5 Likes

@NUTRICORP, I believe I’ve found a solution, if this is what you’re talking about

You can use the Camera.FieldOfView property to change the zoom factor.

Some things to keep in mind:

  • Its not exactly a regular zoom. Its more like camera staying in place and zooming in.
  • Remeber to set the CameraType to Scriptable before changing, and changing it back to Custom after.
  • Of course, make sure you use a LocalScript.

Hope this helps,
JaxsonRox1

1 Like

If you go into studio and run an experience, there is a PlayerModule in your game.Players[YourPlayer].PlayerScripts. This module contains information about how roblox controls your camera, it’s hard to decipher the code, but in due time you should be able to figure it out.

Edit: Everything is a ModuleScript, so you can run the functions inside the scripts.