I’m aware that you can set the camera’s maximum and minimum zoom distances, but I have discovered that there’s a catch: You can’t have the effects be put into action until the player (and this is assuming they even will) decides to scroll with their mouse or pinch their fingers on mobile (presumably).
Basically, I can put distance restrictions on the camera, but they don’t truly “activate” until the player scrolls with their mouse or pinches their fingers. Other than that, all of the code is working fine. Here’s a bit of the code that shows (“ChangeLocation” is a model in the Workspace, and the “camera” inside it is a Part):
It is possible, however, that another solution might be favourable. When the Part begins to tween, the actual camera seems to immediately teleport in what is seemingly a definite amount of studs on the Z axis. Thank you for any advice you can give!
As I know, to set Max zoom to 0, you first need to set min to 0, otherwise max will be equal to min. But if it works well for you, nvm me.
If you set camera CFrame it should handle you, but if it doesn’t, then you can try manipulating Roblox’s own camera script and fire the function that gets fired when mouse wheel is scrolled.
Fire that BindableEvent from your own LocalScript when you want to.
First, test in solo and copy the CameraScript in Player.PlayerScripts. Paste it directly to StarterPlayerScripts after you stop test.
After this, you can figure it yourself and it could be a nice practice for you. Roblox codes are written by professionals and while trying to edit them, trying to read them always gives you one or more things to learn. But I’ll still write if you can’t find out.
What you are looking for is in RootCamera module(It is in the code you just copied). Line 988. You need to fire that function after you get the news with the bindable’s Event. Function needs to be fired from the inside of the function it is since it is a local function. It’s up to you after this.
PS: If anyone else knows a better and easier way, please tell, it would be lovely to learn for all of us too!
Well, you have to remember to set min and max accordingly. For example you want to make it so when you press T you switch between 1st and 3rd person. For third person. you have to set max zoom to let’s say 5 then minimum to 5. Then when you go to first you set min to 0.5 first then max to 0.5 after.
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local first = false
player.CameraMaxZoomDistance = 5
player.CameraMinZoomDistance = 5
UIS.InputBegan:Connect(function(input,typing)
if typing then return end
if input.KeyCode == Enum.KeyCode.T then
if first == false then
player.CameraMinZoomDistance = .5
player.CameraMaxZoomDistance = .5
first = true
else
first = false
player.CameraMaxZoomDistance = 5
player.CameraMinZoomDistance = 5
end
end
end)