Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Mouse inquiry-get mouse, if zoomed in all the way, then remove the cursor?

Asked by
unmiss 337 Moderation Voter
9 years ago

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 :(

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

What you Have To Do

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.


Code

--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
0
Thanks for the well explained answer-but how would I remove the cursor, in the 'if statement' at around line 15. unmiss 337 — 9y
0
I'll edit(: Goulstem 8144 — 9y
0
Does not work :( unmiss 337 — 9y
0
I think line 16 should be target.CFrame.p, not targ alphawolvess 1784 — 9y
0
Keep in mind your answer still is not correct unmiss 337 — 9y
Ad

Answer this question