Vary player speed very precisely

Status
Not open for further replies.

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,702
Reaction score
12,256
First Language
English
Primarily Uses
RMMZ
I would like to vary the walk and dash speeds by very small amounts e.g. make walk 4.2 instead of 4 and dash 4.75 instead of 5 as I've found in my previous games that it makes both speeds feel better.

How would I do that in MZ?
Thanks.
 

Zeireth

Veteran
Veteran
Joined
Nov 2, 2013
Messages
77
Reaction score
56
First Language
English
Primarily Uses
N/A
In the file named rmmz_objects.js within the folder js, there is a line of code named Game_CharacterBase.prototype.realMoveSpeed.

By default it is return this._moveSpeed + (this.isDashing() ? 1 : 0);

_moveSpeed is initialized with a value of 4.

realMoveSpeed is used in Game_CharacterBase.prototype.distancePerFrame. In that function is return Math.pow(2, this.realMoveSpeed()) / 256;

I would highly suggest creating a plugin using any text editor you like, but don't forget to save your file with .js

Within your plugin, you will need to overwrite Game_CharacterBase.prototype.realMoveSpeed and most likely Game_CharacterBase.prototype.distancePerFrame as well, however if you don't care what happens to your core files, then edit them. Be warned whenever a new update comes out and you want to update your project, it will overwrite any and all changes to core files.

Always remember to keep backups of all files in your project. Good rule to follow.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,702
Reaction score
12,256
First Language
English
Primarily Uses
RMMZ
I would highly suggest creating a plugin using any text editor you like, but don't forget to save your file with .js
Sadly I couldn't write a plugin to save my life. I reached the stage where I could do ultra easy things in Ruby, but I moved from VX Ace to MZ only a few days ago and know simply nothing about JavaScript.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,675
Reaction score
2,760
First Language
EN
Primarily Uses
RMMZ
You can use this sort of thing in a Script command to change the player's move speed:

$gamePlayer.setMoveSpeed(4.2);
However, I would recommend a plugin for this, since it's easier to use the built-in dash system and vehicles have a...quirk that makes them reset player speed to 4 on exit rather than preserving the player's previous speed. :kaoslp:

Try this (untested):
JavaScript:
/*:
 * @target MZ
 * @plugindesc Change player walk and dash speed.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/index.php?threads/147948/
 * @help Terms of use: free to use and/or modify for any project.
 */

// Alter player walk speed
(alias => {
  Game_Player.prototype.initMembers = function() {
    alias.apply(this, arguments);
    this._moveSpeed = 4.2;  // walk speed
  };
})(Game_Player.prototype.initMembers);

// Alter dash speed (default is walk + 1, change that by -0.5)
(alias => {
  Game_Player.prototype.realMoveSpeed = function() {
    return alias.apply(this, arguments) - (this.isDashing() ? 0.5 : 0);
  };
})(Game_Player.prototype.realMoveSpeed);

// Restore pre-vehicle move speed when leaving a vehicle
// (By default it resets to speed 4.)
(alias => {
  Game_Player.prototype.getOnVehicle = function() {
    const res = alias.apply(this, arguments);
    if (res)
      this._preVehicleSpeed = this.moveSpeed();
    return res;
  };
})(Game_Player.prototype.getOnVehicle);

(alias => {
  Game_Player.prototype.getOffVehicle = function() {
    const res = alias.apply(this, arguments);
    if (res) {
      // normally resets to 4 here, override that
      this.setMoveSpeed(this._preVehicleSpeed || 4.2);
      delete this._preVehicleSpeed;
    }
    return res;
  };
})(Game_Player.prototype.getOffVehicle);
I think that'll cover all cases for the player.

If you want to affect walk speed for all characters, you can replace this part:
JavaScript:
// Alter player walk speed
(alias => {
  Game_Player.prototype.initMembers = function() {
    alias.apply(this, arguments);
    this._moveSpeed = 4.2;  // walk speed
  };
})(Game_Player.prototype.initMembers);
...with this:
JavaScript:
// Alter all characters' walk speed
(alias => {
  Game_CharacterBase.prototype.initMembers = function() {
    alias.apply(this, arguments);
    this._moveSpeed = 4.2;  // walk speed
  };
})(Game_CharacterBase.prototype.initMembers);
That includes (what I think is) a fix for the speed reset on leaving a vehicle.
[Edit: replaced getOn and getOff with correct name alias.]

  1. Copy + paste the code into a text editor (e.g. Notepad).
  2. File > Save As:
    • File Type: All Files
    • Filename: something.js
      (This works because .js files are plaintext.)
  3. Import that file as a plugin via the Plugin Manager.
  4. Save your project to apply Plugin Manager changes.
  5. Test!
 
Last edited:
  • Like
Reactions: Kes

Zeireth

Veteran
Veteran
Joined
Nov 2, 2013
Messages
77
Reaction score
56
First Language
English
Primarily Uses
N/A
I had done the same as you in the VX Ace times with Ruby. I started learning more about javascript right after the huge scene when a lot of plugin makers got tired of harassment and abuse from fellow community members, because of that I am afraid to post my own plugins that are collecting dust in my folder.

I spent a good amount of time problem solving and getting them to work the way I want them to work. I know years from now, I will look back for nostalgia sake and rewrite them better.

The best place to start is taking your time and understanding the basics. I am no expert or master. A year ago I told myself that it would be too hard. The thing is, if you keep telling yourself that it is too hard or that you can't, then unfortunately you will continue down that path. Switch can't to can. Better your mind with positive thoughts.

I can teach you some of the basics when I have time. I remember a year ago when I wished I had someone to learn from. Feel free to message me directly. I will try to help. First steps in learning are usually the hardest. Remember that it is mostly with the mind.

You can also use a search engine and look up what is javascript function. Read up on functions, syntax, integers, and strings. Those are the building blocks.

1st step: I suggest is downloading notepad++. It is very helpful. The default text editor packaged with Windows or Apple is okay but could do better.

2nd step: Open notepad++.

3rd step: Create a new file with notepad++.

4th step: Save the as Kes_MovementSpeed.js // Now the editor understands that you plan to write in javascript, because of the file type is .js Also // in javascipt is to comment in your script. It doesn't effect your code. In Notepad++ comments are green text.

5th step: Your first line should will be Game_CharacterBase.prototype.realMoveSpeed = function() {

6th step: Your second line will be return 4 + (this.isDashing() ?1 : 0); // Remember your semicolon ; Learn the syntax. Learn what is a javascript function.

7th step: Play with the values 4 and 1 in 6th step.

8th step: Your last line will be }; // Never forget to end your functions with );

9th step: Save the file.

10th step: Move Kes_MovementSpeed.js to your project inside js and into plugins.

11th step: Open your plugin manager in your project, then select Kes_MovementSpeed.js, then maker sure it is on. Press Ok button. // Congrats you made your first plugin. It isn't fully complete. You might notice the first issue, but hey you now got more speed.

Edit: I got caught up on writing that reply for about an hour. Use caethril plugin. caethril is really good and very helpful. Thank you caethril
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,702
Reaction score
12,256
First Language
English
Primarily Uses
RMMZ
@caethyril Thank you so much for that. I've tried it out just on walking (don't have a vehicle set up atm) and it works perfectly.
What do I need to do to change the dash speed from 5 to 4.75? It is just a shade too manic at the default speed for getting round on the type of maps I tend to do. I've done my best at looking at the plugin, but couldn't see any reference to that.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,675
Reaction score
2,760
First Language
EN
Primarily Uses
RMMZ
@Kes - the dashing part is here:
JavaScript:
// Alter dash speed (default is walk + 1, change that by -0.45)
(alias => {
  Game_Player.prototype.realMoveSpeed = function() {
    return alias.apply(this, arguments) - (this.isDashing() ? 0.45 : 0);
  };
})(Game_Player.prototype.realMoveSpeed);
You could replace that part with an override instead if you like:
JavaScript:
// Alter dash speed (walk speed + 0.55)
Game_Player.prototype.realMoveSpeed = function() {
  return this._moveSpeed + (this.isDashing() ? 0.55 : 0);
};
I picked 0.55 because that's the difference between your quoted values, 4.75 and 4.2. [Edit: whoops I just noticed you wrote 4.75. I've edited my numbers to fit. :kaoswt:]

In case it's relevant:
  • There's an Always Dash setting in the in-game Options menu.
  • Touch-based movement always uses dashing speed.

For reference, the default version of that method is this:
JavaScript:
Game_CharacterBase.prototype.realMoveSpeed = function() {
    return this._moveSpeed + (this.isDashing() ? 1 : 0);
};
I.e. normally you move at walk speed +1 when dashing, +0 when not. My original suggestion is a patch that can be read as "default realMoveSpeed, minus 0.45 if dashing". It's -0.45 here because that's the difference between +0.55 (desired dash +speed) and +1 (default dash +speed).

As mentioned, though, an override would probably be totally OK here~
 
Last edited:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,702
Reaction score
12,256
First Language
English
Primarily Uses
RMMZ
@caethyril Thank you for the clarification. I'm afraid that when it comes to coding I have a bird brain (as you might expect given my avatar) and JavaScript is completely new to me. I therefore can miss the most obvious.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,702
Reaction score
12,256
First Language
English
Primarily Uses
RMMZ
@caethyril I seem to have hit a problem.
All was fine when I was just running around the map testing passabilities, but when I went to use Galv's camera plugin (still just running around) I got this error message
1654668066369.png

The console shows this:
1654668152847.png
I'm not trying to get on or off a vehicle, and so have no idea why it's trying to call that.
Once I turned this plugin off the camera command working without a hitch.

Do you have any ideas about this?
Thanks.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,675
Reaction score
2,760
First Language
EN
Primarily Uses
RMMZ
:kaoswt2: Whoops, my mistake! There are a couple of typos in the code I originally suggested:
JavaScript:
    const res = getOn.apply(this, arguments);
JavaScript:
    const res = getOff.apply(this, arguments);
These should each be replaced with:
JavaScript:
    const res = alias.apply(this, arguments);
I just updated my original reply with the correction. Hopefully that fixes the problem, thanks for pointing it out!
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,675
Reaction score
2,760
First Language
EN
Primarily Uses
RMMZ
You're welcome!

Edit:

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Last edited:
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

I made a menu option that pulls a (accurate) version of the world map from my game instead of having a "traditional" world map. How did I do?

1656552400614.png

..Every time after I edit it and repost it I find a new tiny error I made. :kaodes:
1656550526125.png
Town Design is the best part of an RPG. Well, that and dungeon design
I think that this forum's member posts should include their Phone Number and Social Insurance Number.
My PC just broke with everything I've been working on, on it. I can't afford to replace it. Life is just wonderful....
More musics! Praise be to the winter towns!

Forum statistics

Threads
123,178
Messages
1,154,645
Members
161,546
Latest member
Desteyo34
Top