2D Zelda like movement

0 favourites
  • 11 posts
From the Asset Store
A template for a grid movement , grid tactics type game like Dofus , click on the grid you want to move to and the
  • In classic Zelda games when you're moving in a direction, and press two other buttons next to it, you keep the same animations just move diagonally in that direction. Example: Moving upwards (play upwards animation), press left arrow (keep playing upwards animation) but move upward diagonally. Here is a video: youtube.com/watch . I did it so if you press a button such as left, and or not pressing any other buttons, it will play left animation and will continue to do so until you let go of left. Then after that the next button you press it will start playing that animation until you let go of it. So if you press up, it will play up animation, and you can press left to move diagonally, but it will keep playing up animation. The problems is, I hold down up arrow, and then press left, then down, he does a weird moonwalk thing. Please help. If you don't understand anything above, can you please just help me come up with a system for good zelda like movement. PS Im using 8 movement control.

  • If I understand correctly, I would add an instance variable to the player that indicates the player is moving. Then when a button is pressed, check to see if the player is already moving. If they aren't, set your animation going and set the moving variable

    On future button presses, they check to see if moving, and the player is already moving so they skip the animation and press on. You character still moves in the correct directions, but you only set the animation to play if no movement key was being held down prior to the button press.

    That should prevent animations from overriding each other, which is what I suspect is happening here. What you have described is "undefined" behavior, meaning the exact outcome depends on which order you test the movement keys determines the final, actual, animation.

    At least I think. If what I'm saying doesn't make sense, can you post a .capx? We'll be happy to take a look at it (I wouldn't imagine it would be hard to make a new project, copy the player and the movement key events).

    Hope it helps!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If I understand correctly, I would add an instance variable to the player that indicates the player is moving. Then when a button is pressed, check to see if the player is already moving. If they aren't, set your animation going and set the moving variable

    On future button presses, they check to see if moving, and the player is already moving so they skip the animation and press on. You character still moves in the correct directions, but you only set the animation to play if no movement key was being held down prior to the button press.

    That should prevent animations from overriding each other, which is what I suspect is happening here. What you have described is "undefined" behavior, meaning the exact outcome depends on which order you test the movement keys determines the final, actual, animation.

    At least I think. If what I'm saying doesn't make sense, can you post a .capx? We'll be happy to take a look at it (I wouldn't imagine it would be hard to make a new project, copy the player and the movement key events).

    Hope it helps!

    The only issue with that would be going opposite directions. Your system would mean if you were running right then switched to running left, it would keep the right running animation while going left. So you'll need a series of events and sub-events to define when to stick with what animation direction, but it'll work.

    I do it based on button presses.

    If W is down set animation to north

    --subevent: if a, set animation to north,

    --if d, north

    --if s, south.

    Do something like that for each of the four directions and it should cover everything.

  • It works fine when I only have left and right. But once I add the vertical movement it glitches.

  • Hmmm...Yeah, I was assuming a return to idle before going in the opposite direction (no button press), but there's not necessarily anything in the code to cause that, and it would be bad to assume.

    Wouldn't the same thing happen with yours C-7?

    If W is down set animation to north

    --subevent: if a, set animation to north,

    --if d, north

    --if s, south.

    ...

    If S is down set animation to south

    --subevent: if a, set animation to south,

    --if d, south

    --if s, north.

    then the animation is the north animation, regardless of which key was pressed first.

    I think I'm missing something.   <img src="smileys/smiley1.gif" border="0" align="middle" />

    taborgreat, that's probably because of the order of your events. If you reorder them, do you get an issue with a different direction?

  • I don't get what you mean, but here is the capx so you can see what is happening. BTW, I made the link art. Do you guys like it.

    CAPX: mediafire.com/download/jbz9d32daly73zt/Zelda.capx

  • I downloaded your capx and played around with it for a while. It will work if you do the following:

    For the main event:

    If left arrow is down

    AND

    if down arrow / up arrow / right arrow are not down

    Then set animation to walk left.

    Then place the sub events exactly as you have them.

    Do this for right/down and up as well. This will make it so the animations work correctly in all 8 directions.

    You'll still need to add some instance variables or something for when you turn around to make the animations change properly.

  • Thanks, that helped fix some of the bugs, but I still have problems with the animations transitioning properly. Sometimes I walk walk to the left and the walking right animation plays.

  • check your other post, I uploaded a capx for you.

  • This topic could be useful:

    http://www.scirra.com/forum/sprite-movement-8-dir-troubles_topic47201.html

    Anyway discard all your events and i'll show you how to get it working with just two events.

    You can get the direction the sprite is moving with the expression:

    Link.8Direction.MovingAngle

    You can then convert the angle into a number from 0-3 where

    0 right

    1 down

    2 left

    3 up

    Here is the formula. it's explained somewhat in the link.

    int(((self.8Direction.MovingAngle+360+45) %360)/90)

    One more bit. The numbers 0-3 can be converted to the direction names with this: where "dir" is a integer from 0 to 3.

    tokenat("right,down,left,up", dir, ",")

    OK,down to business, add an instance variable to Link and call it "dir". Then make these two events:

    Link| 8Direction is moving

    --- Link| set dir to int(((self.8Direction.MovingAngle+360+45) %360)/90)

    --- Link| set animation to "walk" & tokenat("right,down,left,up", self.dir, ",")

    System| Else

    --- Link| set animation to "idle" & tokenat("right,down,left,up", self.dir, ",")

  • Very nice trick R0J0hound, up until now I would test if the angle is between -45 and 45 degres, then between 46 and 135 and so on... Yours is much ore elegant, thank you

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