Detect when mouse angle is in a range for selection wheel

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 :sweat_smile:)

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!

I’m sorry to bump this but I really need help with it as it is a very important part of the game.

Thanks for the help!

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.

To be honest, I think your best bet IS too make it a 0 to 360 system, and add some seperate code for the fire (e.g. If the final angle, when it is between 0 and 360, is >= 345 OR less than 15) so that it isn’t problematic.

1 Like

That could work. I will try that as soon as I can and will get back to you with the result.

Thanks for the help! I really appreciate it

Hey just got a chance to try out your suggestion and it worked perfectly! Thank you very very much for the help!
I don’t know why I didn’t think of that :sweat_smile:
Thank you very much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.