Is there a way to disable cursor when player is zooming into First Person View?
Yes, you check if the camera is on the player and if the CameraMode is LockFirstPerson or is fully zoomed into player and then set UserInputService.MouseIconEnabled to false. And basically revert said property in the opposite case.
what do you mean by camera on the player? can you give me example?
I believe this will help you: How to Check if a Player is Fully Zoomed in?
Well I don’t have enough time to code a fully optimized script but this LocalScript that you should put into StarterPlayer>StarterPlayerScripts does the job:
local Players = game:GetService("Players")
local lplr = Players.LocalPlayer
local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
runService.RenderStepped:Connect(function()
local char = lplr.Character or lplr.CharacterAdded:Wait()
local isFirstPerson = (camera.CFrame.Position - char.Head.Position).magnitude < 1
if lplr.CameraMode == Enum.CameraMode.LockFirstPerson or isFirstPerson then
userInputService.MouseIconEnabled = false
else
userInputService.MouseIconEnabled = true
end
end)
The only problem occurs when you are zoomed in and start jumping. The mouse sometimes flashes for a short second. You could try increasing the distance comparsion to 2 studs or something and find the sweet spot to mitigate this issue.
And the only other issue that I can currently think about is Guis that have the property “Modal” set to true. This only is an issue though if you use the CameraMode Enum.CameraMode.LockFirstPerson.
Edit: fixed a little mistake i made in the script
a possible way
--LocalScript
task.wait(2)
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local rns = game:GetService("RunService")
local zoom=nil
rns.RenderStepped:Connect(function()
zoom = (camera.CFrame.Position - camera.Focus.Position).Magnitude
uis.MouseIconEnabled = zoom > 1
end)
which one is more accurate compared to the method above?
@2112Jay’s way is shorter and as it uses camera.Focus.Position, it doesnt have this flashing mouse cursor problem mine has. My method ensures that the MouseCursor is hidden when the CameraMode is set to LockFirstPerson, his doesn’t do that, but in retrospective that check is rather unnecessary.
I would go with @2112Jay’s method. It seems more intuitive than mine. The only thing I can’t quite grasp is the definition of the player variable in his script. But you can just remove that line.
Here’s a shorter and slightly less intensive version. Using Stepped keeps it reasonable.
local cam = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local rns = game:GetService("RunService")
rns.RenderStepped:Connect(function()
uis.MouseIconEnabled = (cam.CFrame.Position - cam.Focus.Position).Magnitude > 1
end)
This would be a lot easier if there was a flag to check if the player is in first person mode.
You’re right !! … pure habit at this point.
Started as a testing script.
i can relate, especially when it comes to LocalScripts that are in StarterPlayer you define the player just because of muscle memory
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.