Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Directional movement help.

Chaucer

Towns Guard
Xy$
0.00
Oi~ I've been working on creating a 16 directional movement system today, I've got it to work somewhat, however I seem to be having a bit of trouble with one issue, and I can't seem to figure it out, I'd done something similar with a previous version of rpg maker, however I've been scratching my head trying to making this one work, so here's what I've got right now.
JavaScript:
Game_CharacterBase.prototype.movedir = function(direction) {
    switch(direction) {
    case 0.5 :
        xPlus = -2;
        yPlus =  1;
    case 1   :
        xPlus = -1;
        yPlus =  1;
    break;
    case 1.5 :
        xPlus = -1;
        yPlus =  2;
    break;
    case 2   :
        yPlus = 1;
        xPlus = 0;
    break;
    case 2.5 :
        yPlus = 1;
        xPlus = 2;
    break;
    case 3   :
        yPlus = 1;
        xPlus = 1;
    break;
    case 3.5 :
        yPlus = 2;
        xPlus = 1;
    break;
    case 4   :
        xPlus = 1;
        yPlus = 0;
    break;
    case 6   :
        xPlus = -1;
        yPlus =  0;
    break;
    case 6.5 :
        xPlus = -1;
        yPlus = -2;
    break;
    case 7   :
        xPlus = -1;
        yPlus = -1;
    break;
    case 7.5 :
        xPlus = -1;
        yPlus = -2;
    break;
    case 8   :
        xPlus =  0;
        yPlus = -1;
    break;
    case 8.5 :
        yPlus = -1;
        xPlus =  2;
    break;
    case 9   :
        yPlus = -1;
        xPlus =  1;
    break;
    case 9.5 :
        yPlus = -2;
        xPlus =  1;
    break;
    default  :
    xPlus = 0;
    yPlus = 0;
    break;
 
    }
this._x += xPlus;
this._y += yPlus;
};

this code works, the player moves in the right directions, the only problem is the new directions should be moving like this.

however, everytime I use one of the new movements, it moves like this.


I can't seem to find where the math of how the movements are defined, so I'm not sure where I should apply anything.
P.S. I'm using a pixel movement script, with each tile cut into sixth's found here http://forums.rpgmakerweb.com/index.php?/topic/46493-super-orange-movement-pixel-movement-with-custom-features/
any help/advice is welcome thanks in advance~
 
Last edited:

eivl

Local Hero
Xy$
0.00
How can i replicate it?
[doublepost=1449645852,1449645313][/doublepost]and how many subdivisions are you using on the tiles?
 

Chaucer

Towns Guard
Xy$
0.00
just put the plugin in a game file(it should even work without a pixel movement to be honest, you just won't be able to move until you're back on a solid tile) and call this on console, or make a parallel event with this script call $gamePlayer.movedir(direction) or $gameMap._events[1].movedir(direction), direction being the direction you want to move, anything from 0.5 to 9.5(any float value number moves awkwardly, like the images above, also I've edited the script so that it will be more noticeable using whole tile values for more clarity. and subdivisions on tiles is 6).
 

eivl

Local Hero
Xy$
0.00
You need to write a new moveDiagonally method that takes into account that you can move two steps up and one step to the side (or reverse) the current implementation of this checks if you can move to a diagonal location and then moves the same amount in both axis.
after this it must then choose a horizontal or vertical path.

Here is the current code from SuperOrangeMovement.
JavaScript:
character.prototype.moveDiagonally = function(horz, vert) {
      this.setMovementSuccess(this.canPassDiagonally(this._x, this._y, horz, vert));

      if (this.isMovementSucceeded()) {
        this._x = $gameMap.roundFractionXWithDirection(this._x, horz, this.myStepSize());
        this._y = $gameMap.roundFractionYWithDirection(this._y, vert, this.myStepSize());
        this._realX = $gameMap.fractionXWithDirection(this._x, this.reverseDir(horz), this.myStepSize());
        this._realY = $gameMap.fractionYWithDirection(this._y, this.reverseDir(vert), this.myStepSize());
        this.increaseSteps();
      }

      if (this._direction === this.reverseDir(horz)) {
        this.setDirection(horz);
      }
      if (this._direction === this.reverseDir(vert)) {
        this.setDirection(vert);
      }
    };
  };
What you need to implement is a horse move but have it relate to myStepSize, but i do see one problem, you will also need to keep the sprite direction unchanged during the movement, because i think (based on the original source) that the player sprites will be updated if you move vertical- or horizontally....
[doublepost=1449662822,1449661507][/doublepost]Found something interesting.
JavaScript:
// Useful Direction Constants
var Direction = {
  UP: 8,
  DOWN: 2,
  LEFT: 4,
  RIGHT: 6,
  UP_LEFT: 7,
  UP_RIGHT: 9,
  DOWN_LEFT: 1,
  DOWN_RIGHT: 3,

  goesUp: function(d) {
    return [7, 8, 9].indexOf(d) >= 0;
  },

  goesDown: function(d) {
    return [1, 2, 3].indexOf(d) >= 0;
  },

  goesLeft: function(d) {
    return [1, 4, 7].indexOf(d) >= 0;
  },

  goesRight: function(d) {
    return [3, 6, 9].indexOf(d) >= 0;
  },

  joinDirections: function(dir1, dir2) {
    if (dir1 == Direction.UP || dir2 == Direction.UP) {
      if (dir1 == Direction.LEFT || dir2 == Direction.LEFT) {
        return Direction.UP_LEFT;
      } else if (dir1 == Direction.RIGHT || dir2 == Direction.RIGHT) {
        return Direction.UP_RIGHT;
      }
    } else if (dir1 == Direction.DOWN || dir2 == Direction.DOWN) {
      if (dir1 == Direction.LEFT || dir2 == Direction.LEFT) {
        return Direction.DOWN_LEFT;
      } else if (dir1 == Direction.RIGHT || dir2 == Direction.RIGHT) {
        return Direction.DOWN_RIGHT;
      }
    }

    if (dir1 >= 1 && dir1 <= 9 && dir1 != 5) {
      return dir1;
    } else {
      return dir2;
    }
  },

  getButtonName: function(direction, defaultValue) {
    switch (direction) {
      case Direction.UP:
        return 'up';
      case Direction.DOWN:
        return 'down';
      case Direction.LEFT:
        return 'left';
      case Direction.RIGHT:
        return 'right';
      default:
        break;
    }

    if (defaultValue === undefined) {
      defaultValue = '';
    }

    return defaultValue;
  }
};
and

JavaScript:
var deltaX1 = $gameMap.deltaX(node.x, start.x);
      var deltaY1 = $gameMap.deltaY(node.y, start.y);

      if ($.Param.DiagonalPathfinding !== false) {
        if (deltaY1 > 0 && deltaX1 > 0) {
          return Direction.DOWN_RIGHT;
        } else if (deltaY1 > 0 && deltaX1 < 0) {
          return Direction.DOWN_LEFT;
        } else if (deltaY1 < 0 && deltaX1 < 0) {
          return Direction.UP_LEFT;
        } else if (deltaY1 < 0 && deltaX1 > 0) {
          return Direction.UP_RIGHT;
        }
      }
and

JavaScript:
  Game_Player.prototype.getAlternativeDirection = function(direction, diagonal_d) {
    if (direction != diagonal_d) {
      switch (diagonal_d) {
        case Direction.UP_LEFT:
          return direction == Direction.UP ? Direction.LEFT : Direction.UP;
        case Direction.UP_RIGHT:
          return direction == Direction.UP ? Direction.RIGHT : Direction.UP;
        case Direction.DOWN_LEFT:
          return direction == Direction.DOWN ? Direction.LEFT : Direction.DOWN;
        case Direction.DOWN_RIGHT:
          return direction == Direction.DOWN ? Direction.RIGHT : Direction.DOWN;
        default:
          break;
      }
    }

    return direction;
  };
and

JavaScript:
Game_Player.prototype.executeMove = function(direction) {
    switch (direction) {
      case Direction.UP:
      case Direction.DOWN:
      case Direction.LEFT:
      case Direction.RIGHT:
        this.moveStraight(direction);
        break;

      case Direction.UP_LEFT:
        this.moveDiagonally(Direction.LEFT, Direction.UP);
        break;
      case Direction.UP_RIGHT:
        this.moveDiagonally(Direction.RIGHT, Direction.UP);
        break;
      case Direction.DOWN_LEFT:
        this.moveDiagonally(Direction.LEFT, Direction.DOWN);
        break;
      case Direction.DOWN_RIGHT:
        this.moveDiagonally(Direction.RIGHT, Direction.DOWN);
        break;

      default:
        break;
    }
  };
If you where to add directional logic here it should work.
[doublepost=1449664202][/doublepost]TL;DR

You need to add :
UP_UP_LEFT
UP_UP_RIGHT
UP_LEFT_LEFT
UP_RIGHT_RIGHT

DOWN_DOWN_LEFT
DOWN_DOWN_RIGHT
DOWN_RIGHT_RIGHT
DOWN_LEFT_LEFT

if i god my head screwed on the right way that should work.
 

Chaucer

Towns Guard
Xy$
0.00
nice, this is what I was looking for, however I was looking in everything but the pixel movement script xP lol, also I've got the sprite direction issue solved already, just need to make the movement execute properly thank you, very much for this info, its a big help.
 

Chaucer

Towns Guard
Xy$
0.00
So, I spent quite a while fiddling with this, but it seems every math equation I throw at it results the same thing as the pictures above, the only way I got it to move correctly, was dividing a tile by 48, and moving it by 2:1 spaces, however the move speed seems to drastically decrease, and can't seem to be increased, not even modifying distancePerFrames (or I would have not minded using it this way) anyone here good with math? lol I've tried just about everything I can, and I'm pretty much stumped on this. ^^; I've attempted looking into sanshiro's anolog move script http://forums.rpgmakerweb.com/index.php?/topic/49828-analog-move/, which allows the player to move in full 360, but I still can't figure out what math to use.

edit : nevermind, I had the math right all along, it was something else interrupting with the formula. issue's resolved~
 
Last edited:
Top