Gamepad analog sticks for rotation

0 favourites
  • 7 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hi everyone,

    I was working on the controls for my game and thought it might be cool to aim at the angle the thumb sticks are pointing, much like a twin-stick shooter.

    Right now the controls are set up to only aim at 45 degree angles, but thought finer controls when aiming might be nice. Unfortunately it gets a lot more complicated.

    Does anyone have any ideas on how to set this up? I would really appreciate any advice.


  • All you really need for this is to get the angle at which your analog stick is pointing, which you can get using the following expression:

    angle(0, 0, Gamepad.Axis(GamepadIndex, XAxisIndex), Gamepad.Axis(GamepadIndex, YAxisIndex))[/code:1be38cjs]
    You would, of course, replace GamepadIndex, XAxisIndex, and YAxisIndex with the desired indices for the gamepad and analog stick you're wanting to check on.  After getting this angle, it should be pretty straightforward to point/shoot/whatever an object in that direction.
  • Thanks for the reply linkman2004!

    I hate to say this, for fear that I'm probably going to sound really dumb, but how do I write the expression to find the correct thumbstick and axis? I assumed the gamepad index was 0 since it's player one.

    How about I write what I had as I might not even be close.

    Every tick ---- Gun - Set angle to atan(Gamepad.Axis(0, Index?) / Gamepad.Axis(0, Index?))

    The manual just says, "Index specifies left analog X and Y or right analog X and Y axes, subject to Key mapping. Axes range from -100 to 100.", which is quite vague.

  • The expression to get the angle is going to look exactly as I wrote it, but with the indices replaced -- no need to use atan. I can't give exact indices(depends on the controller), but if I had to hazard a guess I would say:

    GamepadIndex = 0

    XAxisIndex(Left stick) = 0

    YAxisIndex(Left stick) = 1

    XAxisIndex(Right stick) = 2

    YAxisIndex(Right stick) = 3


    The only way to find out for sure is to run tests. Set the angle of an object to the expression I gave with various indices and see what works.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks linkman2004! I will try that out right away.

  • Yep, linkman2004, your indices were correct for the axis and thumbstick.

    Thanks so much for the help!

  • I was just about to post a similar question, thanks to linkman2004 for answering and ryanrbot for beating me to the punch!

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