Eight Directional Movement

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

EightDirMovement1

By default, the game only allows you to move in the four orthogonal directions: up, left, down, right.

This script provides support for eight-directional movement in your game, adding support for  diagonal movement. To move diagonally, hold down two direction keys simultaneously.

This script also adds support for eight-directional character sprites,  allowing you to face the appropriate direction when you are moving diagonally.

Followers can use 8-dir sprites

EightDirMovement6

 

Events can use 8-dir sprites. And of course, you can trigger events diagonally. If you have 8-directional vehicles, they are also supported.

EightDirMovement15

Do you have large sprites? No problem, it supports large sprites as well.

.EightDirMovement20

If you just want to be able to move diagonally, you do not need diagonal sprites to use this script. They will simply walk diagonally using one of the orthogonal sprites.

Download

Script: download here

Tutorials

Interested in how it is written? Read the dev log for this script!

Installation

In the script editor, place this script below Materials and above Main

Usage

In the configuration, you can choose whether you want to use diagonal sprites or not by setting the Use_8Dir_Sprites option to true or false. If it’s true, then diagonal sprites will be used. If it’s false, they will not be used.

If you don’t use diagonal sprites, then you can still walk around diagonally, but the sprites will be facing one of the orthogonal directions.

Spritesheet Specifications

Diagonal sprites require you to follow a specific sprite-sheet format. It assumes you are using the default 3×4 character format on a 12×8 character sheet. This means that if each sprite was 32×32 in size, then your image will be 384×256 in dimensions.

Adding Diagonal Sprites

A full character sheet for one character consists of the orthogonal directions as well as the diagonal directions. You will first place your orthogonal sprites onto the sheet, and then right beside it, place your diagonal sprites.

The sprite directions should be as follows (the index is for reference only assuming it is the first character on the sheet)

EightDirMovement17

This means that you can have up to 4 characters per sheet, though I would recommend reserving one sheet per character set. Note that this example does not reflect how the full image appears; I have cropped it for clarity.

Larger Sprites

If you are using sprites that are larger than 32×32 (or smaller), those are also supported. As usual, you need to follow the same specifications. For example, if each sprite was 64×32, then you would have a 192×192 sheet for one set of animations, and then you need to expand that to a 768×256 sheet to meet the specifications.

If you’re having trouble with your sprites, read part 4 of the dev log to see how it works.

Enable Switch

In the configuration, you can choose a specific switch to use to determine whether 8-dir movement is enabled. When the switch is ON, 8-dir movement is enabled. If the switch if OFF, then 8-dir movement is disabled.

Help spread the word!Share on FacebookShare on TumblrTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditFlattr the author

You may also like...

37 Responses

  1. jfields99 says:

    I am enjoying this script very much, and was wondering how to add a simple compatibility with a WASD Movement script?
    WASD Movement script follows:

    #==============================================================================
    # ▼ WASD Movement
    # -- Last Updated: 2014.02.25
    # -- Author: Helladen
    #==============================================================================

    module Input
    #--------------------------------------------------------------------------
    # alias method: self.dir4
    #--------------------------------------------------------------------------
    class <<self; alias helladen_dir4 dir4; end
    def self.dir4
    return 2 if Input.press?(:Y)
    return 4 if Input.press?(:X)
    return 6 if Input.press?(:Z)
    return 8 if Input.press?(:R)
    helladen_dir4
    end
    end

    • Hime says:

      That script you posted doesn't support diagonal input. I would recommend using full keyboard input for this, by mapping WASD to the direction keys.

      Line 162 of the script might look like this if you wanted both arrows and WASD

      UP = [KEYMAP[:UP], KEYMAP[:LETTER_W]]
      DOWN = [KEYMAP[:DOWN], KEYMAP[:LETTER_S]]
      LEFT = [KEYMAP[:LEFT], KEYMAP[:LETTER_A]]
      RIGHT = [KEYMAP[:RIGHT], KEYMAP[:LETTER_D]]

  2. Thegrop says:

    Would it be possible to disable diagonal walking on passable tiles perpendicular (not sure if that’s the right word) to X tiles? I’m not sure how to explain it in words so here’s a diagram. (The red Xs mean no passability tiles.)

    Basically I want to disable walking diagonally over tiles that are right next to a tile with no passability, for eventing reasons. Would that be possible?

  3. Lo says:

    Err, sorry for that, but… how do I name the diagonal sprite? Some suffix? Like, sprite name is “$Actor”, then do I name the diagonal sprite “$Actor_something”? I have read the script but I didn’t found about this… actually I don’t understand english soooo well x_x

  4. Doodleturd666 says:

    Hey sorry to be such a dummy (I’m a total noob)
    But wtf am I supposed to patch on the multi frames??
    I have your 8 directional movement script and I have modern algebra’s multiple frames…
    However, I have no idea what to do with your patch!
    Lemme know thanks!!

    • Panqueque says:

      Im having the same issue,please help us 🙁
      The characters keep moving with 3 frames(my animations are made with 6 frames)and in diagonal movement uses the next 3 frames of the same animation,im sorry,but i dont know how to explain it better…
      anyway,thanks for creating this script and i hope you can help.

    • Hime says:

      You should be able to just insert both scripts in your project and it should work. If it doesn’t work then something may have changed on the other script, or it wasn’t working in the first place (which would be strange)

  5. Benjamin says:

    Hey Hime thanks so much for the script. I’ve found one optimization that you could make, and that is to move the direction facing to the end like this:

    def move_diagonal(horz, vert)
    @move_succeed = diagonal_passable?(x, y, horz, vert)
    if @move_succeed
    @x = $game_map.round_x_with_direction(@x, horz)
    @y = $game_map.round_y_with_direction(@y, vert)
    @real_x = $game_map.x_with_direction(@x, reverse_dir(horz))
    @real_y = $game_map.y_with_direction(@y, reverse_dir(vert))
    increase_steps
    else
    check_event_trigger_touch_front
    end

    if horz == 4
    if vert == 2
    set_direction(1)
    elsif vert == 8
    set_direction(7)
    end
    elsif horz == 6
    if vert == 2
    set_direction(3)
    elsif vert == 8
    set_direction(9)
    end
    end
    end

    This is because the direction of the player should be calculated even if there’s no move. For example if you walk diagonally into a wall, it should still face diagonally into the wall, because that’s how all the other directions work.

    Cheers, and thanks for the script!

  6. Otaku-kun says:

    Hi Tsukihime.

    Im having the same problem as Cheeky Moon. (Your 8 directional movement script and galv’s character animation script) I also checked in the issues and bug report section but i didnt see anything about this. Do you think you could make a patch for this?

  7. Rizzle says:

    Hey, I really like this script. I also really appreciate all the tutorial stuff. It’s quite fascinating. I just have a simple question. Is there a reason why even on a new project I can’t run diagonally up and to the left? Every other direction works flawlessly. I’ve had this situation with other scripts as well, but I like yours the best.

    • Hime says:

      Could it be your keyboard?

      • Rizzle says:

        That is absolutely the problem… Thanks for the quick response. Now for another simple question. Would you be willing to make this script compatible with Galv’s Jump Script? I would be so grateful, but I would understand if you weren’t taking compatibility requests as well.

      • Rizzle says:

        Yeah, that’s the exact problem. I’m pretty sure I wrote another response, but that was hours ago and it’s still not showing up… I’m glad to see you’re still active. I may be wanting to use some of your scripts in a commercial project. I’ll let you know which ones I’m using eventually here.

  8. Hime says:

    For those using Modern Algebra’s extra animation movements, I’ve written a patch so that extra animations also apply to diagonal frames.

  9. NoizeDaemon says:

    He ho! Awesome script!
    Anyways, I got a question: I plan to only use 8-way-movement on the world map – is there any possibility to enable that movement only for specific map-IDs?

  10. Cheeky Moon says:

    I got a little question, are this diagonal movement compatible with extra animations?
    Or is there a small chance that it will be added?
    I want a Idle pose, walking, running and jumping animation.
    I may want to add the flying script of galv from here:
    http://galvs-scripts.com/2012/11/12/superman-ability/

    I never found any diagonal movement script that is compatible with Galv’s flying script. :/
    I want to fly in specific regions. So much for the planning and thank you in advance. 😀 (\s/)

    • Hime says:

      The way the script is designed is that you have your orthogonal frames in one sheet, and then you have your diagonal frames beside it. There was no particular reason behind this design beyond me choosing something that works. It also assumed you used the default character format. If you have “extra” animations, you’d have to specify what that means and how it looks.

      So theoretically as long as you can place your extra animations in a ortho/diag pattern, it will work.

      Galv’s script does not seem to be changing the way movement is handled so as long as you follow the format with his “_fly” suffix it should work.

      • Cheeky Moon says:

        I was talking about extra animations, like standing, walking and running. The second thing that is allready implemented in my RPG, is that all animations have 6 frames instead of 3. In basic I asked about, how can I use diagonal movement and 6 frame animation. Tried to change some lines in the script, but somehow only messed stuff up. :/
        Really sorry for the late answer, at the moment I’m using Victor Sant scripts for animations like stance, walking, running and jumping also I do so for diagonal movement and 6 frame animations. But Victor Sant’s scripts seems not to be compatible with the flying script of Galv. 🙁
        I got an alternative 6 frame animation from Modern Algebra here:
        http://rmrk.net/index.php/topic,46822.0.html
        And the fly script I’m using from above or here:
        http://galvs-scripts.com/2012/11/12/superman-ability/
        The extra animations can be found here:
        http://galvs-scripts.com/2012/10/04/character-animations/

        What I want is animations for jumping, walking, running, flying, idle with 6 animation frames and diagonal movement. Hope I writen it clear enough. Really sorry for the late reply. :'( (\s/)

        • Hime says:

          Create a new project with the scripts you want and some characters set up with your character format. Then send it to me using the “contact me” form in the navbar at the top of the page.

          • Alopex says:

            Did you ever get this to work? I also happen to be using that same script of galv’s and would love to implement diagonal sprites as well!

  11. Mireneye says:

    Any advice on how i can turn/convert a single character sheet, using $ at 512X288, each sprite is 128×96. Been trying quite a bit but cant quite figure it out. Grateful for any pointers, help. Read the blog but still seemingly unable to fully apply the knowledge. Thanks ^^

    • Hime says:

      I’m assuming the width is 288 and height is 512. Multiply the width by 4 and the height by 2 to get the size of the image if there were 8 of those sheets on the same image.

  12. Zolex Szeto says:

    erm… my character went invisible when i move at 2,4,8,10 clock direction or east south direction why does this happen i copy and paste without changing anything pls reply asap thanks

  13. Ian Bach says:

    hello I een trying to make this script work but I have chars that are 64×32 in size. does this script only work with the 32 x 32 type char sets?

    • Hime says:

      It works with any character size as long as the sheets are 3×4 and you have 8 blocks per image.

      • Ian Bach says:

        I figured out what was wrong.
        so first sprite i made was 3×4 with a 3×4 so one 3×4 was up down etc other was diagonal movements. i tried it without $ with $ with ! and nothing in front of file name no joy.
        so then i figured out it need to be set on a file/picture that is big enough for 8 3×4 sprite sheets. these have no prefix i.e. $ it is just normal file name. so i set the up down to top left 3×4 area and diag moves to the right of that sprite.

        ? is there a way to make to change the sprites when char runs? so 8 dir walk 8 dir run? I ask because some of the sprites I have from one of the rpg maker packs has run and walk all 8 direction. it also has ones that are like 7-9 moves 3 or 4 rows moves are coloumns per say. looks like they are for combat moves. then one sprite sheet has 4 moves looks like char lying down or dead ?

        • Hime says:

          Additional animation modes would require additional scripts. This one simply takes your default 4-dir movement and adds some diagonal movement.

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax