I’m creating a GUI that temporarily uses the user’s scroll wheel to navigate different parts of it and I need to know how to unbind it from Roblox’s core camera zoom in/out functionality and then rebind it afterwards.
I would like to know how you do this as well, do you mind mentioning me in a reply if you do find out?
Mahalo,
Fuse
You can just click this button to be notified.
To the OP, you can probably use ContextActionService and return a sink.
If you plan to make it the main GUI, freezing the player or having it somehow freeze them, you can always use max zoom with min zoom. Or you could do a mouse.hover (I forgot the function name) and have that manipulate the zoom distances
Yea I was thinking about the Freezing the zoom value but I’d rather bind/unbind it through ContextActionService if it’s possible. If no one on here can figure it out though, that’s probably what I’ll end up doing.
Since you are still using the MouseWheel, unbinding it would not solve your problem.
Since it’s just the in/out zooming of the scroll wheel, we can just set the MaxZoomDistance and MinZoomDistance of the Players’ camera to the current zoom, and change them back after its closed.
Now, getting the current zoom of the Players’ camera isn’t a feature that Roblox has, but it is easily calculated.
local player = game.Players.LocalPlayer -- Get the player (for the camera)
local currentZoom = (workspace.CurrentCamera.CoordinateFrame.p - player.Character.Head.Position).magnitude (calc. currentzoom)
local LastMaxZoom = player.CameraMaxZoomDistance -- save the current settings
local LastMinZoom = player.CameraMinZoomDistance -- ^
local isDisabled = false
function ToggleScroll() -- simple on/off function for the zoomies
if isDisabled then -- Scroll is active
isDisabled = false
player.CameraMaxZoomDistance = LastMaxZoom
player.CameraMinZoomDistance = LastMinZoom
else -- scroll is inactive
isDisabled = true
player.CameraMaxZoomDistance = currentZoom
player.CameraMinZoomDistance = currentZoom
end
end
I know you want to do ContextActionService, but I honestly have no idea what the bind ActionName would be for the in/out on the scroll wheel anyhow. This is probably the only way to go about it right now.
Alrighty, thank you!
Mahalo!
Just to add to your answer, here’s a more compressed version of it that I’m going to implement in my GUI.
local player = game.Players.LocalPlayer
local MaxZoomCache,MinZoomCache = player.CameraMaxZoomDistance,player.CameraMinZoomDistance
function ToggleScroll(b)
local CurrentZoom=(workspace.CurrentCamera.CoordinateFrame.p - player.Character.Head.Position).magnitude
player.CameraMaxZoomDistance,player.CameraMinZoomDistance = ((not b and CurrentZoom) or MaxZoomCache),((not b and CurrentZoom) or MinZoomCache)
end
This is the proper method if you want to temporarily disable certain input types using ContextActionService: you need to sink its input. It is also a far more reliable AND easy method than caching zoom and setting it every frame (no shade intended, @legosweat - this would be a nice solution, but there is a better way to go about it).
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:BindAction(
"Action",
function ()
return Enum.ContextActionResult.Sink
end,
false,
Enum.UserInputType.MouseWheel
)
Here is the code necessary. To unbind it, just call ContextActionService:UnbindAction("Action")
.
cc @TwoFuse, since you had the same question
Thanks for the tip, the more you know.
Was never really caught up on the ContextActionService, so I gave it my best shot.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.