• home
  • forum
  • my
  • kt
  • download
  • Home / 2D Graphics / Flash / Games /

    Top down 8 way movement

    Author: 2008-10-08 12:30:59 From:

    Here’s another old tutorial that I’ve bought over from the previous site, showing you how to create nice and simple 8 directional movement with rotation, handy for top down games such as RPG’s and the like.

    I’ll probably carry this tutorial on at a later date to make a full game from it, until then, here’s the old one.

    FrozenHaddock Tutorials: 8 Way Movement

    In this tutorial, we’re going to create simple, 8-way, top-down movement. This is easy to implement and effective to use.

    car
    First, draw what you want to move.
    You need to draw it facing upwards for the rotation to work.

    carselected
    Now select your character.

    converttof8
    Hit F8, and convert the car to a movie clip.

    actionspanel
    Open the actions panel for the car.
    To do this, select the movie clip and hit F9.

    ActionsOne
    Now, this script creates the 8 way movement.
    Unfortunately, this doesn’t make the character rotate.

    longerscript
    This needs to be added into the previous script.

    rotatescript
    And lines need to be added into the existing script.

    So, the full script you have on there should be this-

    1. onClipEvent(load){
    2. speed=5;
    3. }
    4. onClipEvent(enterFrame){
    5. if(Key.isDown(Key.LEFT)&&Key.isDown(Key.UP)){
    6. this._x-=speed;
    7. this._y-=speed;
    8. this._rotation=315;
    9. }
    10. else if(Key.isDown(Key.LEFT)&&Key.isDown(Key.DOWN)){
    11. this._x-=speed;
    12. this._y+=speed;
    13. this._rotation=225;
    14. }
    15. else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.UP)){
    16. this._x+=speed;
    17. this._y-=speed;
    18. this._rotation=45;
    19. }
    20. else if(Key.isDown(Key.RIGHT)&&Key.isDown(Key.DOWN)){
    21. this._x+=speed;
    22. this._y+=speed;
    23. this._rotation=135;
    24. }
    25. else if(Key.isDown(Key.LEFT)){
    26. this._x-=speed;
    27. this._rotation=270;
    28. }
    29. else if(Key.isDown(Key.RIGHT)){
    30. this._x+=speed;
    31. this._rotation=90;
    32. }
    33. else if(Key.isDown(Key.UP)){
    34. this._y-=speed;
    35. this._rotation=0;
    36. }
    37. else if(Key.isDown(Key.DOWN)){
    38. this._y+=speed;
    39. this._rotation=180;
    40. }
    41. }

    This should produce this

    This can be used in many types of games, particularly RPG’s.

    Bookmark and Share

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      3D (20)
      Math Physics (14)
      3rd Party (5)
      Navigation (60)
      Actionscripting (26)
      Optimization (16)
      Animation (32)
      Projector (9)
      Audio (46)
      Special Effects (112)
      Backend (25)
      Text Effects (65)
      Drawing (18)
      Tips and Techniques (41)
      Dynamic Content (25)
      Tricks (6)
      Games (90)
      Utilities (21)
      Getting Started (91)
      Video (24)
      Interactivity (43)
      Web Design (29)

    New

    Hot