How do I break gamepad joystick into 12 equal parts?

0 favourites
  • 7 posts
From the Asset Store
Set of 12 Parallax Background to make pixel art game.
  • 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

  • angle(0,0,Gamepad.Axis(0, 0), Gamepad.Axis(0, 1)) is the angle of the left thumbstick

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

    every tick - set sprite angle to angle(0,0,Gamepad.Axis(0, 0), Gamepad.Axis(0, 1))

    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

    every tick set rectangle angle to angle(0,0,Gamepad.Axis(0, 0), Gamepad.Axis(0, 1))

    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)

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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

  • 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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)