How do I move with analog control on controller with 8 direction?

0 favourites
  • 2 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • i want it to move with the controller like most games where the more you move It to the left the faster it is, how do i do that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you have your basic controller movement set up?

    You'll add to that with an event that adjusts the 8direction maximum speed, proportional to the distance your stick is from the center.

    To get the distance from center, you want sqrt(gamepad.axis(gamepad,indexX)^2,gamepad.axis(gamepad,indexY)^2)

    indexX and indexY are the numbers of the x and y axes of the gamepad respectively, I'm guessing 0 and 1 but I'm not sure.

    Divide that by 100 to get a value between 0 and 1, and use the resulting number to limit your maximum speed proportionally with the lerp expression so...

    Every tick set sprite 8direction max speed to lerp(0,definedmaxspeed, (sqrt(gamepad.axis(gamepad,indexX)^2,gamepad.axis(gamepad,indexY)^2))/100)

    definedmaxspeed is your maximum speed in a single direction. Note that diagonals will exceed this speed. There's probably a better way around this but I can't think of it at the moment.

    Now there's going to be a problem where the maximum speed is set to 0 immediately after releasing the stick, which will stop your character right away and I'm assuming that would be undesirable.

    So instead, you would set the maximum speed to the higher of the two values between current speed and stick speed limit by using the max(a,b) expression. Resulting in...

    max(sprite.8direction.speed,lerp(0,definedmaxspeed, (sqrt(gamepad.axis(gamepad,indexX)^2,gamepad.axis(gamepad,indexY)^2))/100)

    Unfortunately I don't have a gamepad to test with so I'm almost certain I made a mistake in there or overlooked something, so that's why I wrote out the thought process. Let me know how it goes.

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