Skip to main content

InputObjectTracker

Tracks an input object, whether it's a mouse or a touch button for position or mouse down.

Works around a bug in the mouse object where the mouse input objects are new per a mouse event.

local maid = Maid.new()
local tracker = maid:Add(InputObjectTracker.new(initialInputObject))

maid:GiveTask(RunService.RenderStepped:Connect(function()
	print("Input down at", tracker:GetPosition())

	-- Can also cast a ray
	print("Cast ray at", tracker:GetRay())
end))

maid:GiveTask(tracker:ObserveInputEnded():Subscribe(function()
	maid:DoCleaning()
end))

maid:GiveTask(tracker.InputEnded:Connect(function()

end))

Functions

ObserveInputEnded

InputObjectTracker:ObserveInputEnded() → Observable

Observes when the input is ended

GetInitialPosition

InputObjectTracker:GetInitialPosition() → Vector2

Gets the initial position for the input object

GetPosition

InputObjectTracker:GetPosition() → Observable<Vector2>

Observes input object position

GetRay

InputObjectTracker:GetRay(
distancenumber?--

Optional number, defaults to 1000

) → Observable<Vector2>

Observes the input object ray

SetCamera

InputObjectTracker:SetCamera(cameraCamera) → ()

Sets the camera for the input object tracker to retrieve rays from

Show raw api
{
    "functions": [
        {
            "name": "ObserveInputEnded",
            "desc": "Observes when the input is ended",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 88,
                "path": "src/inputobjectutils/src/Client/InputObjectTracker.lua"
            }
        },
        {
            "name": "GetInitialPosition",
            "desc": "Gets the initial position for the input object",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Vector2"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 97,
                "path": "src/inputobjectutils/src/Client/InputObjectTracker.lua"
            }
        },
        {
            "name": "GetPosition",
            "desc": "Observes input object position",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Vector2>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 106,
                "path": "src/inputobjectutils/src/Client/InputObjectTracker.lua"
            }
        },
        {
            "name": "GetRay",
            "desc": "Observes the input object ray",
            "params": [
                {
                    "name": "distance",
                    "desc": "Optional number, defaults to 1000",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Vector2>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 121,
                "path": "src/inputobjectutils/src/Client/InputObjectTracker.lua"
            }
        },
        {
            "name": "SetCamera",
            "desc": "Sets the camera for the input object tracker to retrieve rays from",
            "params": [
                {
                    "name": "camera",
                    "desc": "",
                    "lua_type": "Camera"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 136,
                "path": "src/inputobjectutils/src/Client/InputObjectTracker.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "InputObjectTracker",
    "desc": "Tracks an input object, whether it's a mouse or a touch button for position\nor mouse down.\n\nWorks around a bug in the mouse object where the mouse input objects are new\nper a mouse event.\n\n```lua\nlocal maid = Maid.new()\nlocal tracker = maid:Add(InputObjectTracker.new(initialInputObject))\n\nmaid:GiveTask(RunService.RenderStepped:Connect(function()\n\tprint(\"Input down at\", tracker:GetPosition())\n\n\t-- Can also cast a ray\n\tprint(\"Cast ray at\", tracker:GetRay())\nend))\n\nmaid:GiveTask(tracker:ObserveInputEnded():Subscribe(function()\n\tmaid:DoCleaning()\nend))\n\nmaid:GiveTask(tracker.InputEnded:Connect(function()\n\nend))\n```",
    "source": {
        "line": 30,
        "path": "src/inputobjectutils/src/Client/InputObjectTracker.lua"
    }
}