Analogue Stick Directions

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hi peeps - is there an easy way to get the direction from an analogue stick? At present the only values you can obtain are the horizontal and vertical position and unfortunately my maths is a bit sketchy these days :(

    I'm just testing things at the moment and am trying to get a turret to always look in the direction of the right stick.

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

  • I don't claim to know how to best go about this, and I don't have the XNA exporter yet, but...

    Cos and Sin would probably be the way to go math wise, but you can do the same with Advanced Direction Object, and have the angle of the turret set to Direction Between Two Points, giving the first point X=0,Y=0 and the second point the horizontal and vertical positions you got from the gamepad.

    The above is assuming the analog stick has 0,0 for center point, but if not, then you need to figure out what the X and Y of the center are and use those for the first point. When using the Joypad object, the center point seemed to be max_value/2 for both axises, as the top-left corner of an analog stick of an X360 gamepad (on a PC anyways) gives roughly a position of 0,0 and the bottom right is something around 65500,65500 or something. Joypad was able to fetch the max values, I think.

    Don't quote me on any of that though. It's just how I think it was. ;P

    Edited once, last by HitmanN (June 6, 2012 at 11:59 AM).

  • Thanks V - the Xbox sticks returns 0,0 for dead centre and -/+100 for maximum directional push.

    I've got to be honest, I was expecting there to be an expression for directional value!


    Edit - just noticed the Direction Calculator object has a convert XY into direction - this can be combined with the X & Y positions of the sticks to successfully work. Thanks for the tip in the right direction.

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

    Edited once, last by Asholay (June 6, 2012 at 2:29 PM).

  • Glad you got it figured out. It's really just basic maths when you look at it. I didn't have any trouble setting it up when I was testing it. The dir calc works too of course. :)

    Please login to see this link.|Please login to see this link.|Please login to see this link.
    Need art for your game? I'm currently available for work.
    3D Modeler, Rigging TD, Animator for hire - Please login to see this link.
    Please login to see this link.

  • What method do you use? I'd far sooner use the correct maths than an extension as it'll be better on mem and space.

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

  • I used this method with a recent shooter game I am working on:

    Quote

    ATan2((StickRightV*-1.0), StickRightH)

    Converts the axis values to an angle.

    Creator of Please login to see this link. & Please login to see this link.. Always working on some exciting game development projects! Check out the latest at : Please login to see this link.

    Follow me on twitter Please login to see this link.

  • That's exactly the sort of thing I was looking for thanks, but I can't quite get it to work for me - it just spins around with any input given. I'm avoiding the trig, but something tells me I need to get some books out again :S

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

  • Actually, done some more testing with counters watching everything and ColeJs method does work perfectly - but for some reason, the horizontal and vertical values returned by the gamepads is a bit touch and go?

    Pressing forward goes from 0 to -100 perfectly, but pulling down works it's way towards +100, then when it hits +100, it provides a -100 reading instead??

    Does that happen for you guys as well?


    Edit: only seems to do it when testing through Windows, works ok on xbox... bah, there's so many slight differences between running on win & box!

    IndieDB Page: Please login to see this link.
    Development Blog: Please login to see this link.

    Edited once, last by Asholay (June 9, 2012 at 4:49 PM).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!