I want to make the mouse cursor disappear when the player zooms into first person. How would I do that?
robloxapp-20240906-1733211.wmv (1020.6 KB)
If they’re always in first person, you can just configure UserInputService.MouseBehavior
and UserInputService.MouseIconEnabled
.
If you have a keybind to switch between both first person and third person, you can just configure those properties when toggling between views.
If you want to let the player keep full control over the camera zoom, you can check for when the camera’s distance to the head of the player is zero (or somewhere close to zero), where the camera is considered to be in first person view.
Do a playtest, and copy the player module (inside of the player scripts) and copy that into StarterPlayerScripts.
Next go to the TransparencyController module (located in PlayerModule → CameraModule.
Next on line 179 in the “Update” function, you will now be able to tweak the settings.
function TransparencyController:Update(dt)
local currentCamera = workspace.CurrentCamera
if currentCamera and self.enabled then
-- calculate goal transparency based on distance
local distance = (currentCamera.Focus.p - currentCamera.CoordinateFrame.p).magnitude
local transparency = (distance<2) and (1.0-(distance-0.5)/1.5) or 0 -- (7 - distance) / 5
if transparency < 0.5 then -- too far, don't control transparency
transparency = 0
end
-- tween transparency if the goal is not fully transparent and the subject was not fully transparent last frame
----------------- THE MAIN PART OF THE FUNCTION YOU WILL EDIT ---------------------
if self.lastTransparency and transparency < 1 and self.lastTransparency < 0.95 then
local deltaTransparency = transparency - self.lastTransparency
local maxDelta = MAX_TWEEN_RATE * dt
deltaTransparency = math.clamp(deltaTransparency, -maxDelta, maxDelta)
transparency = self.lastTransparency + deltaTransparency
UserInputService.MouseIconEnabled = true --- ADD THIS LINE RIGHT HERE
else
UserInputService.MouseIconEnabled = false -- ADD THIS LINE AS WELL
self.transparencyDirty = true
end
------------------------------------------------------------------------------------
transparency = math.clamp(Util.Round(transparency, 2), 0, 1)
-- update transparencies
if self.transparencyDirty or self.lastTransparency ~= transparency then
for child, _ in pairs(self.cachedParts) do
if VRService.VREnabled and VRService.AvatarGestures then
-- keep the arms visible in VR
local hiddenAccessories = {
[Enum.AccessoryType.Hat] = true,
[Enum.AccessoryType.Hair] = true,
[Enum.AccessoryType.Face] = true,
[Enum.AccessoryType.Eyebrow] = true,
[Enum.AccessoryType.Eyelash] = true,
}
if (child.Parent:IsA("Accessory") and hiddenAccessories[child.Parent.AccessoryType]) or child.Name == "Head" then
child.LocalTransparencyModifier = transparency
else
-- body should always be visible in VR
child.LocalTransparencyModifier = 0
end
else
child.LocalTransparencyModifier = transparency
end
end
self.transparencyDirty = false
self.lastTransparency = transparency
end
end
end
Now add the lines that I marked up (UserInputService required) and then whenever the player is in first person, their cursor will be removed.