I'm currently making a RPG game. In the game there are longbows. Because the longbows shoot far, I think it'd be great if while holding the bow you could zoom in by pressing the right mouse button. How do I make a script that allows for "Zooming in"? I've looked at some models in the ROBLOX catalog but none of them work and some just change the camera view. How do I actually make it so you could zoom in?
To "make it zoom in" it is most necessary to adjust the camera view.
You can access the Camera
from a LocalScript
using workspace.CurrentCamera
.
To produce an effect such as the one you describe you will probably be interested in the FieldOfView
property.
You can get a reference to the Mouse
object being used by the Player
using game.Players.LocalPLayer:GetMouse()
.
Once you have a mouse object, you can connect a function (or functions) to the Button2Down
and Button2Up
events.
mouse = game.Players.LocalPlayer:GetMouse() while not workspace.CurrentCamera do wait() end --Wait for the camera camera = workspace.CurrentCamera mouse.Button2Down:connect(function() --Decrease Field of View (zoom) camera.FieldOfView = 40 --Ranges from 80 (wide) to 20 (narrow) end) mouse.Button2Up:connect(function() --Return to default camera.FieldOfView = 70 end)
That should get you started!