Hello, I have been working on an FPS game and I want to give it a nice animation when the player drags his mouse on the x axis. But I don’t know how to detect if the player is dragging his mouse on a certain axis, How do I do that?
Thank you!
Here’s a script I made to check for X axis mouse movement. Remember that this must be in a local script to be able to get mouse movement.
local Players = game:GetService("Players")
local mouse = Players.LocalPlayer:GetMouse()
local lastX = 0
mouse.Move:connect(function()
local MouseX = mouse.X - lastX
if MouseX > 0 then
print("Mouse moving on X axis")
end
lastX = mouse.X;
end)
Thank you, it works but not in first person. (I added it to the title of the post)
My bad, didn’t realize that. In first person camera movement is manipulated by any raw mouse movement. I’ll try to get back to you with a script on how to accomplish this.
Alright, here’s what I came up with. I’m in class at the moment so sorry about my response time. I read up on ContextActionService and I was able to make it work with first person X axis movement checks. Let me know how I can improve the script or if it’s what you need.
local contextService = game:GetService("ContextActionService")
local function IsMovingCam(input)
if math.abs(input.Delta.X) > 0 then
return ("Moving X Axis")
end
end
contextService:BindAction("CameraMovement", function(a,b,input)
print(IsMovingCam(input)) end, false, Enum.UserInputType.MouseMovement)
Thank you it works like a charm! But I have a question, is there a way to check if the mouse is being dragged left or right?