Any ideas on how to get the direction or angle (North, South, East, West, North-East, etc.) of the movement of the mouse from Button1Down
to Button1Up
?
Illustration of what I mean:
Any ideas on how to get the direction or angle (North, South, East, West, North-East, etc.) of the movement of the mouse from Button1Down
to Button1Up
?
Illustration of what I mean:
Here is a script of knowing the direction of where the mouse is going you can Basically edit that so it can just be MouseButton1down or Up or even knowing where north is etc
local mouse = game.Players.LocalPlayer:GetMouse()
local lastx,lasty
mouse.Move:Connect(function()
local x,y,directionX,directionY = mouse.X,mouse.Y
if not lastx then
lastx,lasty = x,y
else
directionX = ((x > lastx) and "Right") or "Left"
directionY = ((y < lasty) and "Up") or "Down"
lastx,lasty = x,y
end
if directionX and directionY then
print(directionX.." | "..directionY)
end
end)
Why do you need this?
I feel like you probably aren’t actually trying to get the Cardinal direction of the mouse, and are really asking something else.
At a high level what are you trying to do?
I’m trying to make a sword that will slash based on the direction of the mouse. When the mouse moves to the right, the sword will slash to the right. You get the point.
You can do something that looks like this
local mouse = game.Players.LocalPlayer:GetMouse()
local lastMouseX, lastMouseY = 0, 0
mouse.Move:Connect(function()
local mouseX, mouseY = mouse.X, mouse.Y
local deltaX, deltaY = mouseX - lastMouseX, mouseY - lastMouseY
local angle = math.acos(deltaY / deltaX)
local magnitude = math.sqrt(deltaX ^ 2 + deltaY ^ 2)
lastMouseX = mouseX
lastMouseY = mouseY
print(angle, magnitude)
end)
I quickly wrote that so it might be wrong. It gets the angle and the magnitude