I'd like for the game to remove your cursor when you're zoomed in all the way-but I'm not sure how to check if you're zoomed in.
I'm not asking for much! Please don't moderate this :(
I'd like for the game to remove your cursor when you're zoomed in all the way-but I'm not sure how to check if you're zoomed in.
I'm not asking for much! Please don't moderate this :(
To detect if you're zoomed in then you need to check the distance from the camera's CoordinateFrame to the Character's Head. Since, when you're zoomed in then the camera is closer to the head. And if you're in first person then the camera is in the vicinity of 1 stud away from the head. So you just need to compare the distance from the Camera's CoordinateFrame to the Character's Head to 1. If it is then remove the mouse icon.
How To Compare Distance From Camera To Head
There's a property of the camera called CoordinateFrame. CoordinateFrame stands for CFrame. This property is the location of the camera. You can compare the distance between the camera's CoordinateFrame and the Character's Head using magnitude.
Magnitude?
Magnitude is the length of a vector, and is often used to find the distance between two points.
To get the difference between two vectors, you subtract one from the other. Normally put as b - a whereas a is the starting point and b is the ending point.
So getting the difference between two vectors looks like this:
Vector3.new(10,0,0) - Vector3.new(0,10,0).
Now this creates a whole new Vector - Vector3.new(10,-10,0).
And then we use magnitude to get the length of this vector!
Vector3.new(10,-10,0).magnitude
which translates to something like 14.142. 14.142 is the length of the difference between these two Vectors.. the Distance!
How to Remove the Mouse Icon
The Mouse's icon is defined by a property of the mouse.. called Icon. If you set this to nothing then the mouse icon will disappear.
But, you want to bring it back when they zoom out, correct? So just save the current icon before you change the icon, then reset it if they go out of bounds.
--Get the Camera
local cam = workspace.CurrentCamera
--Get the player
local plr = game.Players.LocalPlayer
--Get the mouse
local mouse = plr:GetMouse()
--Get the default icon
local icon = mouse.Icon
--Wait until the character exists, then get the head.
repeat wait() until plr.Character
local target = plr.Character.Head
while wait() do
--Get the distance from the camera's CoordinateFrame to the Head with magnitude
local dist = (target.CFrame.p - cam.CoordinateFrame.p).magnitude
--See if distance is less than 1
if dist <= 1 then
--Set the icon to a transparent decal
mouse.Icon = 'http://www.roblox.com/asset/?id=33410686'
else
--Check if the icon isn't already the default
if mouse.Icon ~= icon then
--If so, reset it.
mouse.Icon = icon
end
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
Thanks for the well explained answer-but how would I remove the cursor, in the 'if statement' at around line 15.
I'll edit(:
Does not work :(
I think line 16 should be target.CFrame.p, not targ
Keep in mind your answer still is not correct