Mouse Lock On Mobile

Whenever you touch the screen of your mobile device, it moves the mouse even though I’m setting LockCenteron a renderstepped loop. Is there a way to remove this behavior?

The movement of the mouse on mobile is not based on Roblox logic, it’s OS based. Roblox cannot take control of the mobile mouse due to how mobile operating systems work.

1 Like

There is no way to remove this behaviour and you shouldn’t have a reason to either. Naturally, because mobile doesn’t have a mouse, MouseBehaviour wouldn’t function the same way. Input on mobile devices is based on the positions of screen touches by the user.

Sounds like you’ve run into an XY problem. What are you trying to do? Vague questions without a defined use case are difficult to answer adequately.

I lock mouse to center of screen and make character face the mouse, on mobile it starts facing whenever you touch the screen.

I’m going to go ahead and assume that you’re positioning the character based on mouse.Hit. I have to make this assumption with the limited information provided in this thread. That is where I tell you not to use that and instead change to a camera-based method.

If you explicitly need something that works akin to mouse.Hit, look into ViewportPointToRay. Extend a ray, get the position at the end of the ray and supply that for your functions instead. You probably won’t need to extend the ray though when you can use Ray.Direction over mouse.Hit.p.

If i want to account for collsions, I would use a raycast instead shouldn’t I?

Sure you can. ViewportPointToRay generates a unit ray so you just have to extend it by however much you want (there’s a code sample available on that page) and use any of the FindPartOnRay* functions. These search the ray until a hit point is found or the end of the ray is reached. Remember that raycast functions return a tuple: you will want to use the position return.

If you need to ignore collisions, that’s what the ignore lists are for.