Walk animation

This forum is currently in read-only mode.
From the Asset Store
Character Sprite Pack: Walk 4 Directions made in illustrator
  • Hi, I'm wondering how you can i can make my player walk when he walks left or right and then stops when you don't move, I'm using platform movement.

  • Heya, Casho my boy. I feel sorry for ya, kid. Nobody seems to want to help you out. Well, me and Johnny.jpg got yer back.

    Check it, yo:

    <img src="http://xs223.xs.to/xs223/08035/johnnyrunning929.gif">

    How To Run, starring Johnny.jpg:

    http://www.mediafire.com/?bhexmhksmxh

    See Johnny. See Johnny run. Run, Johnny, run! But how does Johnny run? We put the default Platform movement on him, but it's not enough. He just sorta slides back and forth. So we make a new animation for him called "Running" and fill it with some running frames. Check it out in the Animator Bar.

    But there's a problem... he doesn't know how to move his feet when he runs! Johnny's not too bright. We have to tell him when to move his feet, like so:

    <img src="http://xs123.xs.to/xs123/08035/howtorun1158.jpg">

    Event 1 triggers when you have the right key down. It tells Johnny to which angle to face, and to switch to his Running animation. But we don't want any interference from the left control key, so we put in an inverted trigger for "Move Left is down." We also only want Johnny to face the angle and switch to his animation only once when we push right, so we add the System trigger "Trigger once." This keeps him from setting his animation to Running every cycle (which means you would only ever see the first frame of the animation).

    Next, we set it up so that when there are no movement controls pressed, Johnny goes back to standing still:

    <img src="http://xs223.xs.to/xs223/08035/howtorun2129.jpg">

    Easy enough. At this point though, you may be wondering why we're using "Control is down" and "Trigger once" instead of just "On control pressed." Basically, it's because game players are sloppy! They mash the keys around when they're playing, so sometimes both left and right is pressed at the same time. This causes problems, like having poor Johnny go moonwalking around the screen. To compensate for this we put in the inverted controls to keep actions from happening on sloppy key presses, like so:

    RIGHT DOWN, LEFT NOT DOWN - Run right

    LEFT DOWN, RIGHT NOT DOWN - Run left

    RIGHT NOT DOWN, LEFT NOT DOWN - Stop running

    But there's one key combo left that we have to compensate for to refine our controls:

    RIGHT DOWN, LEFT DOWN - Stop running

    But the way the default Platform movement is set up, it's a bit tricky to do this. When you have both keys down, Johnny still wants to run in whatever direction you pressed last. You could conceivably do this:

    <img src="http://xs123.xs.to/xs123/08035/howtorun3763.jpg">

    BUT this leads to problems. The Platform -> Stop action stops all movement, including jumping, and even falling! Yikes! We need something that will make a smooth transition from pressing left and right that won't make Johnny grind to a halt every time the player mashes both control keys. A better way would be like so:

    <img src="http://xs123.xs.to/xs123/08035/howtorun4632.jpg">

    Now, this might seem a little weird at first, but trust me... it works pretty well. We want Johnny to ease to a stop (or into a quick turnaround) with momentum instead of grinding to an immediate halt. So we set the Platform movement to ignore user input when both left and right are pressed. Since this only happens very briefly when someone is playing a game, the transition from right to left movement is pretty seamless.

    So, what's the event right above that for? Well, if you tell Construct to start ignoring user input, then whenever someone presses both keys down Johnny will become unresponsive. We add that event to bring input back each cycle. We're using two events to serve one purpose.

    So, why don't we just set up an Else event right after checking for both keys down, instead of putting the "johnnySprite -> Platform -> Is moving" event in? Well, I tried that and it didn't work, that's why. He slid around like he was on ice when I did it that way. I don't know why. All I know is that this way it works, and the Else event didn't.

    Also, this isn't necessarily the best way to do this. This method of restricting controls could be a little buggy down the line if you wanted to add more complex controls. It's just to give you an idea of how you can customize the default Platform movement to suit your needs. Once you get this down I'm sure you can come up with your own method of doing things.

    Anyway, I hope this helps.

    P.S. -

    Don't steal my tiles, or Johnny will bust your ass.

  • Thanks that works great. But I have a question I'm wanting to have a jump animtation that can turn left and right judging on what angle you were at when you jumped. Be able to turn left and right in the air with 2 different angles, and not go out of the jump animation until the player lands.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yep, I thought that was coming next.

    You will need detectors. Make a plain sprite a few pixels tall, and as wide as your sprite. Set it just underneath your sprite, like so:

    <img src="http://xs223.xs.to/xs223/08036/detector600.png">

    Now make your detector invisible, and update it's position to your player's feet each cycle. That way you have a new condition you can work with:

    "footDetector overlaps groundSprite" and

    "NOT footDetector overlaps groundSprite"

    I'm sure you can see the usefulness of this <img src="{SMILIES_PATH}/icon_wink.gif" alt=":wink:" title="Wink" />

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