Zoom in camera function

Hi there,

For my game i wanted to lock the camera on a certain angle and i found a solution for this to do it. But when i use this script the game wont let the player zoom in and out anymore. I tried to find a solution for this, but so far without succes. I know in the script it is locked aswell.

The code i have so far:

local offset = Vector3.new(-35,50,35)
local fieldOfView = 40
local player = script.Parent.Parent
local camera = game.Workspace.CurrentCamera
local runService = game:GetService("RunService")

camera.FieldOfView = fieldOfView
local function onRenderStep()
 
 local playerPosition = player.Character.HumanoidRootPart.Position
 local cameraPosition = playerPosition + offset
 camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)
end

runService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onRenderStep)

Anybody knows a solution to this?

With kind regards,

You’re probably aware of this, but the reason I can’t zoom out is because you’re manually setting the camera to a constant zoom out position every frame.

As far as I can tell you have two options. You can either clone the default camera scripts and make your edits there. Or you can make your own zoom variable and create your own zoom function. The first one would be preferable. The second one has many issues (like it won’t smoothly transition back), but will technically work.

It is worth noting if you never intend to relinquish control back to the Camera script then the second option would likely be better as most issues are related to switching back to the camera script.

I don’t think the script is written in a way where you can really disable the ability to rotate the camera but leave the rest intact, but I could be wrong.

Editing the default script should be relatively easy once you find the spot you need to edit.

Thank you for your reply! I tried to look into the default camera script, but i was not able to find this one?
And for the second option, this one is way over my head.