Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

2 comments

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.