Character Movements (Idle, Walk and Run)

fbu

Villager
Member
Joined
Mar 22, 2013
Messages
10
Reaction score
11
First Language
Portuguese
Primarily Uses
Character Movements (Idle, Walk and Run)

DESCRIPTION:
Allows for player movement to cycle between 3 character sheets: idle, walk and run.

EXAMPLE:


CODE:

Code:
/*
  <Character Movement>
  v 0.1 - 31 August 2019
  GIT_HUB:
  https://github.com/andrefcasimiro/rpg_maker_mv_js/blob/master/Project1/js/plugins/CharacterMovement.js
  DESCRIPTION:
  Allows for switching between 3 different character sheets: Idle, Walk and Run, according to our movement state.
  INSTRUCTIONS:
  1. Copy and paste plugin.
  2. Choose Idle, Walk and Run character sheets in the plugin's parameters window.
  3. Run game.
  PARAMS:
  @param Actor_{ID}
  ID - must be equal to the actor index in the database
  @param {Pose}_{ID}
  Pose - must be one of the following: 'Idle', 'Walk' or 'Run'
  ID - can be anything as long as you don't repeate @param names
*/

/*:
* @plugindesc Allow for player movement to cycle between 3 character sheets: idle, walk and run.
* @author FBU <andrefcasimiro(at)gmail.com>
*
* // ACTOR 1 --------------------------------
* @param Actor_1
*
* @param Idle_Actor1
* @desc "The character set for idle movement"
* @require 1
* @dir img/characters/
* @type file
* @parent Actor_1
*
* @param Walk_Actor1
* @desc "The character set for walk movement"
* @require 1
* @dir img/characters/
* @type file
* @parent Actor_1
*
* @param Run_Actor1
* @desc "The character set for running movement"
* @require 1
* @dir img/characters/
* @type file
* @parent Actor_1
*
*/

(function() {
  var Parameters = PluginManager.parameters('CharacterMovement');

  var bank = [];
  Object.keys(Parameters).forEach((parameterKey, index) => {
    var parameterKeyArray = parameterKey.split('_');
    var lastIndex = parameterKeyArray && parameterKeyArray[parameterKeyArray.length - 1];

    var isID = parameterKeyArray[0] === 'Actor' && !isNaN(lastIndex);
    if (isID) {
      bank = bank.concat({
        actor: lastIndex,
        sheet: {},
      });
    } else {
      if (!Parameters[parameterKey]) {
        return;
      }
      var key = parameterKeyArray;
      key.length = key.length - 1;
      key = key.join('_');

      if (bank[bank.length - 1]) {
        bank[bank.length - 1].sheet = {
          ...bank[bank.length - 1].sheet,
          [key]: Parameters[parameterKey],
        };
      }
    }
  })

  var actors = [];
  var isDashing, isWalking = false;
  var isStopped = true;
  var action = 0;
  var _cachedAction;

  var Scene_Map_Create = Scene_Map.prototype.create;
  Scene_Map.prototype.create = function() {
    Scene_Map_Create.call(this);

    actors = bank.map(entry => $gameActors.actor(entry.actor));
  };

  var Scene_Map_Update = Scene_Map.prototype.update;
  Scene_Map.prototype.update = function() {
    Scene_Map_Update.call(this);

    managePlayerMovement();
  };

  var setSheet = function(action) {
    actors.forEach(function (actor, index) {
      if (!Object.keys(bank[index].sheet).length) {
        return;
      }

      actor.setCharacterImage(bank[index].sheet[action], actor.characterIndex())
    });
  }

  var managePlayerMovement = function() {
    isDashing = (!!$gamePlayer.getInputDirection() && $gamePlayer.isDashing()) || !!$gameTemp.isDestinationValid();
    isWalking = !!$gamePlayer.getInputDirection() && !isDashing;
    isStopped = !isWalking && !isDashing;

    if (isStopped) {
      action = 0;
    } else if (isDashing) {
      action = 1;
    } else if (isWalking) {
      action = 2;
    }

    if (action !== _cachedAction) {
      action === 0
        ? setSheet('Idle')
        : action === 2
            ? setSheet('Walk')
            : setSheet('Run');

      $gamePlayer.refresh();
    }

    _cachedAction = action;
  }
})();
[See also on Github]

TERMS:
Can be used freely in commercial and non-commercial projects. No credits required.

Any code suggestions / improvements are welcome.

Enjoy!
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,165
Reaction score
8,428
First Language
English
Primarily Uses
RMMV
@fbu Can you please add credits and terms of use to your original post?
 
  • Like
Reactions: fbu

Tea's Jams

I'm human
Global Mod
Joined
Mar 28, 2017
Messages
1,020
Reaction score
2,525
First Language
English
Primarily Uses
RMMZ
Very nice!
 

Therrao

Villager
Member
Joined
May 7, 2017
Messages
8
Reaction score
17
First Language
English
Primarily Uses
RMMV
hi there, i tried it but doesn't seem to work.1588164390412.png
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I've been debating on this as the title screen for a while now...
Ami
--- Dialog Filter ---

Gunner: Yo! my ****** friend?
Hero: Uhh,what happen with your mouth?
Gunner: Huh? what ****** happen with my mouth? i just speech as usual.
Hero: But,your mouth are like the garbage!
Gunner: Hey,what the **** are you say? you want the piece of **** with my ****** Gun!
(Meanwhile,The Dialog Filter In The Option Is Off)
Demo for Maze of the Lost MZ released. I would appreciate any and all feedback and constructive criticism. If you like Dungeon Crawlers and JRPG's with a hint of Metroidvania and Shadowgate/Uninvited you might like it. https://forums.rpgmakerweb.com/index.php?threads/maze-of-the-lost-mz-demo-port-from-mv.127971/
Well, here it is, colored. :kaoslp:

Forum statistics

Threads
103,389
Messages
998,961
Members
134,907
Latest member
zelda3469
Top