How can I move my sprite in 8 directions?

0 favourites
  • 6 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • I have a question... I have a sprite designed in 8 directions... up... down... left... right... up-right... up-left... down-right and down-left. ..

    My problem is that I can't differentiate when it goes in the diagonals from top right left and bottom left right... to be able to load the images corresponding to that animation... how could I do it... I can only identify up, down, left and right.

    I attached an image of the code.

    Tagged:

  • I'm really new to Construct 3, so my answer may not be the right one here, but for what it sounds like you're trying to achieve, I think you need to use the angles functions in order to make this work. So if your player's angle of movement is greater than 340 but less than 10 degrees (north-ish), you'd show the sprite that shows him facing upwards. Or some variation of that. Repeat for each angle group until you have the sprite facing the direction the player is expected to be going.

    This is assuming that angles starts with 0 at true north, which I THINK it does, but I don't remember.

  • Here is one way of doing it, I made a small demo on this thread:

    https://www.construct.net/en/forum/construct-3/how-do-i-8/animations-face-enemy-171414

  • The problem is that the gamepad does not have any function that returns the angle that you are pressing on the controller.

  • Compare Axis is the function I would look at.

    If left Analog X Axis = -100 and left analog y axis = 0 then sprite is whatever frame/s that point it left.

    Repeat seven more times for your eight directions.

    X = 0, Y = 100 (Down)

    X = 0, Y = -100 (Up)

    X = 0, Y = 100 (Right)

    X = 0, Y = -100 (Left)

    X = 100, Y = 100 (Down Right)

    X = 100, Y = -100 (Up Right)

    X = -100, Y = 100 (Down Left)

    X = -100, Y = -100 (Up Left)

    -EDIT- Now that I'm thinking about it, you may want to set these numbers at 1 (or mess with the Comparison), not 100. 100 would mean the sprite wouldn't change unless the stick was all the way pushed. You probably want it to change faster than that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You want to use the "Is within Angle" condition instead of what you have used in your events.

    You can get the gamepad left stick angle by using angle(0,0,Gamepad.Axis(0,0),Gamepad.Axis(0,1)).

    This will return values from 0 to 180 and 0 to -180 which you can convert to 360° angles if you like (not neccessary but I think it's cleaner) by checking for values less than 0 and adding 360.

    Example below

    Now you can use the "Is within Angle" conditions in your code to compare that angle and set the appropriate movement and sprite.

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