Problem with getting Mouse.Hit with tool on mobile

I want to make a gun system that works on mobile. When Tool.Activated is fired, I get the mouse’s CFrame using Mouse.Hit and draw a bullet path from the player’s hand towards that point.

The problem is if the player is moving using the mobile joystick, Mouse.Hit will sometimes give the moving finger’s 3D CFrame instead of the one that activated the tool. I need to make it so I always get the right CFrame.

2 Likes

After a week of failed attempts, I found success in one method: Using the TouchTapInWorld event of the UserInputService. This particular event will only fire when the user touches the world, and it also has the position of the screen that the user touched as a parameter. Having these two requirements met, we can always get the position in the world that the player intended to attack.

Any other method, such as listening to Tool.Activated and then instantly getting Mouse.Hit, has a 50% chance of failure during movement, because of the thumb handling the joystick. What was needed was a way of getting the position of the particular finger that triggered the event, from the event; getting it separately risked failure.

4 Likes