Weapon wheel? how do i make one

I’m not very good at explaining things but, I found this devfourm post on how to make a GTA-like weapon wheel. And one guy showed how to get the angle, but I have absolutely no idea how to select the stuff.

If a player had 8 tools, they could do mouseangle < 90 and mouseangle > 45 like mentioned in the post, but what if the player didn’t have 8 tools how would I calculate if they had 3 items… for example.

divide 360 by the ammount of tools, always start at the top line (as in the image)


(alternatively you could just always have 8 slots and leave the unused ones empty, a lot of games do that)

how would i make this work :skull:

this is all i got and it doesnt really work


	local numOfTools = 3
	local ok = 360 / numOfTools
	
	if Degrees < ok then
		print("test")
	elseif Degrees < ok + ok then
		print("test2")
	elseif Degrees < ok + ok + ok then
		print("test3")
	end

well it does, but if i change num of tools to a different number then it doesnt work

you didn’t change the ammount of prints I’m assuming (no test4, if you say changed it to 4)

im just asking if there is a more robust way of doing this, than having to manually add if statements for every item a player has

I’m sorry I can’t write the code atm because I’m not at my pc but I’d just use a simple algorithm to find the tool:
-say a player has 5 tools (so 72 degrees per segment)
-the mouse it at 227 degrees
for loop running through until it finds:
if 227 <= i x 72 (i starts at 1, then goes to 2 and so on)
when it goes through (in our case) the 4th loop:
if 227 <= i (which is 4) x 72 (which equals 288) then you know since it’s the 4 th loop that the slot will be slot 4

I’m nit the greatest at explaining so if you don’t understand anything please ask

wait u smart hold up let me try to write teh code

local numOfTools = 3
local ok = 360 / numOfTools
for i = 1, numOfTools do
	if Degrees <= i*ok then
		
	end
end

something like this? (degrees is where the mouse is at)

essentially this:

local slots = 7
local degPerSegment = 360 / 7
local mouseDeg = idk this (example 183 degrees)
local slot = nil

for i=1, slots do
    if mouseDeg <= i * degPerSegment then
        slot = i
        break
    end
end

nit 100% sure if this’ll work but please test it and lmk

I think you’d have to break it or use until, otherwise it’ll always be the last slot, you need it to stop for the first slot that meets the criteria or check if the remainder is smaller than the offset (how much bigger it is than the degrees per segement)

it works bro youre smart :skull: never thought of that, thanks for the help

1 Like

Happy I could help, best of luck with your game

1 Like

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