Hello! So I am working on a selection wheel for different abilities and am having an issue with the angles. (I don’t even know how to describe what I am trying to do so I am trying my best )
Here is an image of my wheel:
Here is my code for getting the mouse angle:
local function pointToMouse(frame)
local frameCenter = frame.AbsolutePosition + (frame.AbsoluteSize/2)
local endPos = Vector2.new(Mouse.X, Mouse.Y)
local length = (frameCenter - endPos).Unit
local angle = math.deg(math.atan2(length.Y, length.X)) - 90
return angle
end
And math for detecting range:
if Angle >= Quad.Start and Angle < Quad.End then
My issue is that I have a database for all the angle ranges for each ability. (Angle detection runs on 180 to -180) and it works fine until it gets to the negative numbers.
Here is my database:
local Thresholds = {
Fire = {
Start = -15,
End = 15,
Name = "Fire",
Description = "Fire Description Test",
},
Strength = {
Start = 15,
End = 45,
Name = "Strength",
Description = "Strength Description Test"
},
Earth = {
Start = 45,
End = 75,
Name = "Earth",
Description = "Earth Description Test"
},
Air = {
Start = 75,
End = -255,
Name = "Air",
Description = "Air Description Test"
},
Lightning = {
Start = -255,
End = -225,
Name = "Lightning",
Description = "Lightning Description Test"
},
Teleportation = {
Start = -225,
End = -195,
Name = "Teleportation",
Description = "Teleportation Description Test"
},
Poison = {
Start = -195,
End = -165,
Name = "Poison",
Description = "Poison Description Test"
},
Healing = {
Start = -165,
End = -135,
Name = "Healing",
Description = "Healing Description Test"
},
Water = {
Start = -135,
End = -105,
Name = "Water",
Description = "Water Description Test"
},
Cry10 = {
Start = -105,
End = -75,
Name = "#10",
Description = "Test Description Test"
},
Cry11 = {
Start = -75,
End = -45,
Name = "#11",
Description = "Test Description Test"
},
Cry12 = {
Start = -45,
End = -15,
Name = "#12",
Description = "Test Description Test"
},
}
return Thresholds
As you can see, once it gets to Air it breaks as it is trying to check if the angle is greater than 75 and less than -255 (which is obviously impossible)
I could make it a 0 to 360 detection easily but then there’s the issue of Fire being a range of 345 to -15 which again is impossible.
Just wondering what I am doing wrong or if there is a better way of doing this.
I tried my best to explain my issue so I apologize if it was confusing.
Thanks for the help!