# How do I break gamepad joystick into 12 equal parts?

Get help using Construct 2

### » Wed Jul 29, 2015 11:21 pm

Hello forum people,

First, I would like to thank everyone on these forums. Every time I have asked a question I have gotten an answer and one step closer to finishing my game. So thanks. But I have another...

I want to break the joystick up into 12 equal parts. I did it for 8 equal parts, and that was easy, but when I go to 12 I have a lot of problems. I understand the axes are -100 to 100 but I'm having difficulty with it. I have a wheel menu (kind of like choosing a weapon in gta or red dead redemption) that is 12 equal parts and I want to wheel the joystick around so you can choose each option.

Any help would be greatly appreciated. Thanks
B
12
S
2
Posts: 42
Reputation: 734

### » Wed Jul 29, 2015 11:36 pm

so you can set and invisible sprite object to that angle every tick

then if you check the angle of that sprite eg: it will give you a value between 0 and 360 degrees

you can then divide that angle by 12 or however many slices as you need

The easiest way for a GTA type circle weapon picking thing would be to create a invisible rectangle with a pivot point at one end. Place it in the center of your selection ring.

then use

on button press if rectangle is overlapping circle piece, then select that weapon.

use it as a cursor of sorts to pick which slice is selected.

this way you dont have to deal with any math either.. (i'm sure there's a fancier mathematical way to do this)
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,572

### » Wed Jul 29, 2015 11:44 pm

Ok i looked it up, the fancy math way is

Every tick set text.text to (angle(0,0,Gamepad.Axis(0, 0), Gamepad.Axis(0, 1)) % 360 + 360) % 360

that gives you a value of the gamepad thumbstick axis between 0-360

but the rectangle method as described above is easier to wrap your head around probably
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,572

### » Thu Jul 30, 2015 12:49 am

justifun wrote:Ok i looked it up, the fancy math way is

Every tick set text.text to (angle(0,0,Gamepad.Axis(0, 0), Gamepad.Axis(0, 1)) % 360 + 360) % 360

that gives you a value of the gamepad thumbstick axis between 0-360

but the rectangle method as described above is easier to wrap your head around probably

That seems super nifty keen.

How exactly did you "Look it up" ? Did you go to google and search radial selection or something along those lines?

(Don't mind this next question, I would just appreciate it if someone would humor me - Humor me as in, I have little idea of whats going on and would like to know more)
So.. Why the % 360 + 360 ) % 360 ...... Why the 720 in total? What exactly does this mean? - It's probably one of those situations where "Don't worry about it just copy it down and know that this does this" But I'm curious as to how this is broken down.
B
6
S
2
Posts: 60
Reputation: 1,242

### » Thu Jul 30, 2015 1:33 am

By looking it up i used the search function and searched for "converting gamepad axis to 360 degrees and someone had posted that math equation. I suck at math so i dont know why it works, but it does
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,572

### » Thu Jul 30, 2015 3:54 am

Nice. Thanks. Yeah the -100 to 100 on the axis confused me. This gives me that angle measurements and that's what I was looking for. Thank you, I'm gonna give it a shot tomorrow. I'll let you know how it turns out
B
12
S
2
Posts: 42
Reputation: 734

### » Thu Jul 30, 2015 2:41 pm

@SwatHound

The %360 + blah blah blah is to turn the value into degrees, 360 degrees.

If you do it with out that it will give you values based on how the axis is laid out in Construct 2, -100 to 100 for both x and y axis.
B
12
S
2
Posts: 42
Reputation: 734