Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is it possible for to find the direction the mouse is moving?

Asked by 6 years ago

My goal is to be able to make a sword combo system. I want to have the game determine which combo to use depending on which way the player moves there mouse. Example if the player moves there mouse right then left then right again it would do that series of animations for the combo. How would i go about doing this? and is there an API for finding out each direction of their mouse?

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago
Edited 6 years ago

I wanna explain this more, but basically it's just comparing the last mouse's coordinates with the current mouse's coordinates mathematically whenever it moves.

If currentX is greater than lastX then it's going right.

If currentX is less than lastX then it's going left.

If currentY is greater than lastY then it's going down.

if currentY is less than lastY then it's going up.

local mouse = game.Players.LocalPlayer:GetMouse()
local lastx,lasty;

mouse.Move:Connect(function()
    local x,y,dirx,diry = mouse.X,mouse.Y;
    if not lastx then 
        lastx,lasty = x,y;
    else
        dirx = ((x > lastx) and "Right") or "Left";
        diry = ((y < lasty) and "Up") or "Down";
        lastx,lasty = x,y;
    end
    if dirx and diry then
        print(dirx.." | "..diry);
    end
end)
0
I was thinking that but i also would need to find out the order the person moves theri mouse. Example if he moved up then to the right or if he moved it to the right then up ZeonMaxwelll 75 — 6y
0
You can do that for yourself mate. 'dirx' is Left or Right, and 'diry' is Up or Down. Save a table of the previously used directions, and compare it with your desired combo. Goulstem 8144 — 6y
Ad

Answer this question