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

Locking the mouse at one point

Asked by 10 years ago

I have a third person camera, and it currently locks the player from zooming in or out, and it also makes the person follow where the mouse is going. What i need now is to make the mouse lock at one position on the screen. How would i start ? Here is the Cam script

local abs = math.abs

local distance = 5
local zoom = 70
local sensitivity = 0.25
local height = 1

local player =  game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = Workspace.CurrentCamera

while not camera do
        Workspace.Changed:wait()
        camera = Workspace.CurrentCamera
end
while not mouse do
        wait(0.5)
        mouse = player:GetMouse()
end

wait()

local char = true
local gyro, head, torso

camera.CameraType = "Scriptable"
camera.FieldOfView = zoom

while wait() do
        if char ~= player.Character then
                char = player.Character
                while not char do
                        char = player.CharacterAdded:wait()
                end
                torso = char:WaitForChild "Torso"
                head = char:WaitForChild "Head"
                gyro = torso:FindFirstChild "lookatmouse" or Instance.new "BodyGyro"
                gyro.maxTorque = Vector3.new(0, 7000, 0)
                gyro.cframe = CFrame.new(0, 0, 1) + torso.Position
                gyro.Name = "lookatmouse"
                gyro.Parent = torso
        end
        local hit = mouse.Hit
        if mouse.Hit.p.magnitude ~= 0 then
                local objhit = torso.CFrame:pointToObjectSpace(hit.p)
                local pos = head.Position + Vector3.new(0, height, 0)
                local focus = CFrame.new(pos)
                local vec
                if abs(objhit.x) > objhit.z and
                        (objhit.x/objhit.y)^2 + (objhit.z/objhit.y)^2 > 1 then
                        vec = mouse.Hit.p - pos
                else
                        vec = camera.CoordinateFrame.lookVector
                end
                pos = pos - vec.unit * distance
                camera:Interpolate(
                        CFrame.new(
                                pos,
                                vec + pos
                        ),
                        focus,
                        sensitivity
                )
                gyro.cframe = mouse.Hit
        end
end

1 answer

Log in to vote
0
Answered by
jobro13 980 Moderation Voter
10 years ago

I will give a really short but final answer, as there ain't really other things to say. It is currently impossible to lock your mouse in a position.

However, as what I would consider a very, very hackish method is to equip a tool (this to get the "tool mouse" ) and set the icon to a complete transparant (invisible) image. Now you can use a GUI (or image label) to create a mouse cursor which you can "lock" by not moving the GUI itself around.

Please note that in that case the normal mouse will still work. You will also have to change how the camera works.

In theory this is possible, but I am afraid that this will look really bad in practice.

Ad

Answer this question