I created a module that is supposed to be exactly like
Mouse but with support for mobile & Xbox and more additional features such as allowing tables for TargetFilter.
I have not tested it so I would like to release this as open-source for people to test it out and as something they can probably use.
Depending on if this seems to be a substantial resource, I may move it to #resources:community-resources.
MouseModule.lua (5.9 KB)
You may have already seen a mouse module in the Community Resources section, it is not cross-platform and is a very simple module whereas this one is intended for cross-platform support.
Note: The Mouse object is actually used itself in the module so this is more like an extension to the Mouse object but with UserInputService support as some things can only be done with the Mouse object such as changing the icon but generally I tried to not use the Mouse object as much as possible.
Here are some things that are different in the module than in the actual Mouse object:
- Events receive an argument (
processed) which is a boolean value telling if it was processed on the game or not. If you don’t understand then treat it as a boolean that says whether the player’s mouse is on GUI (
falseif on GUI).
- Setting the icon to
falseis possible, this will disable the mouse icon. Setting it to
truewill enable the mouse icon. It does not however change the image of the icon.
- There is a set max distance for how far a 3D position of the mouse can be found using raycasting, you can set this at the top of the module. It is by default
- TargetFilter accepts a table or instance. If you use a table, it will use the contents of the tables as instances to filter out, no more using a folder when you can use a table instead to filter.
- The Origin property is slightly different from the Origin property of the actual
Mouseobject. I take the camera’s CFrame for this since it’s the closest I can get.
What did I use to make a Mouse alternative?
By using an InputObject’s position that is a Vector2 value and the events
InputEnded then using the following functions below as a unit ray that is used for the raycast for functions that relate to where the mouse is in 3D position.
- :ViewportPointToRay() for PC
- :ScreenPointToRay() for non-PC
MouseEnabled property of UserInputService to know if the player is on PC or not. (Well, they could still be on PC but if you have no mouse, I just count it as non-PC)