How to detect mouse movement's direction in first person?

I have been trying to make a custom first person camera controller for a part of my game.

I’ve tried going with mouse.Move:Connect() and it does fire when moving the cursor, but the issue arises when trying to see in which direction the mouse is trying to move.

Here’s that part of the script:

local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local prevMouse = {X = mouse.X, Y = mouse.Y}


local function MouseMove()
	print(mouse.X - prevMouse.X)
	print(mouse.Y - prevMouse.Y)

	prevMouse.X, prevMouse.Y = mouse.X, mouse.Y
end

mouse.Move:Connect(MouseMove)

The problem is that because of the player being in first person the cursor is locked in the middle (which is preferable as it’s first person) and therefore the mouse doesn’t really move.

So the script just constantly prints out 0 of movement for both the X-axis and the Y-axis.

Some help would be greatly appreciated :heart:

Well, after a few minutes of some more digging and testing I found this post:
How to detect mouse.Move in first person?

And then testing the way of using UserInputService instead of Player.Mouse I managed to find a way to get the mouse movement in first person.

So I’ll be posting the way I found in case someone else runs into the same problem as me.

local UIS = game:GetService("UserInputService")

UIS.InputChanged:Connect(function(input, gpe)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		print(input.Delta)
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.