Free ActionScript

Flash AS2 & AS3 Tutorials, Game Code, Effects, Source Files & Sample Downloads

Smooth 4-way Player Movement

4 Comments »

This Flash game example shows you how to create smooth 4-way player movement with acceleration & friction. This fla also shows you how to create a screen-wrap effect (think asteroids).

Custom Settings:

  • max velocity
  • acceleration
  • friction

Preview

Download Fla Sample

Download Fla Sample

4 Responses

only thing those who use this might wish to add is

if(velocityX || velocityY < aLowNumber){
velocityX and velocityY =0;
}

just to stop the drift that happens as they come to a stop, 0.00846 is just enough for distract your eye.

The author of this site is truely an awesome. I use his as2 works as inspiration for my as3 works

  • That’s a very good suggestion EightySeven.

    It’s a good idea to use a “stopper” for everything that moves. If you’re moving something less than 0.05 pixels for example, it doesn’t move visually, but flash is still redrawing everything in the background using up CPU cycles.

    Thanks for the complement! :)

  • I tried to copy and paste EightySeven’s code into my project but it didn’t work, so I wrote my own:

    if(velocityX < 0.05 && velocityX > -0.05){
    velocityX = 0;
    }
    if(velocityY < 0.05 && velocityY > -0.05){
    velocityY = 0;
    }

    It’s also AS2, so it’ll work for all you who haven’t migrated to AS3 yet.

    - Noah

  • Leave a Reply

    You must be logged in to post a comment.