0 Favourites

How do I set player speed relative to gamepad stick pressure

  • Hello,

    I thought it would be a fairly easy thing to do but I'm really struggling with this one.

    I'm trying to set the player speed relative to the intensity with which the left stick is pushed. (i.e. : The less I push the stick, the slower I am)

    I've tried a couple things but nothing seems to work perfectly, especially in 8 directions. Just try and move in circles, it's not exactly smooth.

    Thanks in advance.

  • To get the best restults, I would recommend using a custom system for movement with an analog stick rather than using the 8-direction behavior. You'll be using angle() and the axis 0 and 1 values to get the angle of the stick, and distance() for the amount with 0,0 as your first two values.

    The 8-direction plugin, after all, is meant 8 directions only.

  • I see.

    I used what I found in 'How do I create smooth 360 degree movement on a controller?' post for the angle, but I don't really get the distance part.

    Right now the player smoothly rotate 360 degrees but how should I tell him to move depending on stick impulse ?

    EDIT :

    I might have found a not so bad solution.

    I attached a bullet behavior to my player rather than an 8 direction. On top of the 360 direction I spoke of earlier, I'm setting the bullet speed relative to which ever gamepad axis value is higher than the other.

    It might not be optimal but it does the trick.

    Thanks a lot for your help !

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • That's a creative solution! Here is how I was thinking just FYI.

    I wouldn't use atan, as you have an extremely slim chance to divide by 0 and I'm not sure how C2 would handle that. Maybe there are safeguards built in and it would be ok, but I'm not sure. Use the angle() expression instead.

    I was thinking would be to set angle , then use the action move forward based on distance, or just move at angle.

    (I'm assuming axis 0 is x and 1 is y, swap them if I'm wrong)

    Angle = angle(0,0,gamepadaxis(0,0),gamepadaxis(0,1)

    Distance = distance (0,0,gamepadaxis(0,0),gamepadaxis(0,1)

    Optional - Multiply distance by a speed multiplier.

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