How to make 8 Direction move at the angle of the gamepad joystick?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • I'm struggling to figure out how to move my character at the exact angle of the gamepad joystick using any of the movement options in C3. I'm currently using 8 Direction but it only simulates at up, down, left, or right. Which doesn't support joystick angles very well. I can force the joystick to only move in those cardinal directions but then the joystick feels weird and unresponsive.

    Is there a way to fix this? I've tried MoveTo and Custom movement but none of do all the things I want. I need the movement to handle acceleration, decelleration, and collision detection at a minimum. But the sliding of 8 Direction is a massive bonus.

    If no one can think of anything then please add a thumbs up to my suggestion:

    github.com/Scirra/Construct-feature-requests/issues/493, which is to add "Simulate at angle" to 8 Direction movement.

  • which is to add "Simulate at angle" to 8 Direction movement.

    You don't need it, because there are "Set vector X/Y" actions. You can set it directly to gamepad axis values:

    Player Set vector X to Gamepad.axis(0,0)
    Player Set vector Y to Gamepad.axis(0,1)
    

    Or calculate stick angle and distance:

    set a to angle(0,0, Gamepad.axis(0,0), Gamepad.axis(0,1))
    set d to distance(0,0, Gamepad.axis(0,0), Gamepad.axis(0,1))
    

    Then use these formulas to move the character:

    Set vector X to cos(a)*d
    Set vector Y to sin(a)*d
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Be wary of the distance() from gamepad sticks, as it's returning values in a square-ish shape and not a circle. Meaning distance can be over 100 on diagonals.

    A simple fix would be just limiting distance i.e min(distance, 100)

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