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!

Inverting Movement with Event in MV (plugin or script request)

snacktaveous

Villager
Xy$
0.00
Hi!

I've been spending a couple of days fruitlessly working with common events and plugins while trying to easily toggle on and off inverted movement controls.

Does anyone know of a script or plugin (or anything else! hoo boy) that can easily reverse movement controls but can also be turned off and on with an event or common event?

What do I plan on using inverted movement controls for?

A dungeon that has timed flare-ups of heat that temporarily reverse movement controls during the flare-ups on the screen. The controls go back to normal when the screen goes back to normal (the crazy-heat goes away). So I need to be able to toggle the controls back and forth on a timer for what I'm hoping to do with it.

Attempts so far:

Common events get the general idea across but the player isn't able to run any longer, and they take two steps instead of one when starting in any direction.

Yanfly's ButtonCommonEvents was slightly better but still didn't do what I wanted. Instead of taking two initial steps in any direction with a common event, the player stutters a step forward and then moves normally. But still no ability to sprint.

The closest I got was Yanfly's KeyboardConfig since movement could be inverted if switched to a WASD configuration but there was no control over toggling this on and off outside of a customizable menu accessible to the player (unless I gave players instructions to pause the game and take it upon themselves to rebind their keys every ten seconds, this probably wouldn't work, especially because that'd screw up immersion and the flow of the game)

Thanks for any assistance with troubleshooting! Not only will I be grateful for your assistance but so will the wall that I've been banging my head into.
 

Xilefian

Adventurer
Xy$
0.00
I consider this a messy solution, but you could just invert the directions of the player input method:
JavaScript:
Game_Player.prototype.getInputDirection = function() {
    return this.reverseDir( Input.dir4 );
};
Game_Player has the method "reverseDir", which conveniently inverts a direction, using this on the input value should cause the movement keys to invert.

So how would you turn this into a (very basic) Plugin?
JavaScript:
( function() {

var INVERT_SWITCH = 1;

Game_Player.prototype.getInputDirection = function() {
    return $gameSwitches.value( INVERT_SWITCH ) ? this.reverseDir( Input.dir4 ) : Input.dir4;
};

} )();
Now whenever switch 1 is set to true, the controls should be inverted (this code is untested, I haven't got MV installed at the moment, but the logic should be sound).

Change the value of INVERT_SWITCH to whatever switch number you'd like to use (so for switch #123 it would be var INVERT_SWITCH = 123;).
 

snacktaveous

Villager
Xy$
0.00
I consider this a messy solution, but you could just invert the directions of the player input method:
JavaScript:
Game_Player.prototype.getInputDirection = function() {
    return this.reverseDir( Input.dir4 );
};
Game_Player has the method "reverseDir", which conveniently inverts a direction, using this on the input value should cause the movement keys to invert.

So how would you turn this into a (very basic) Plugin?
JavaScript:
( function() {

var INVERT_SWITCH = 1;

Game_Player.prototype.getInputDirection = function() {
    return $gameSwitches.value( INVERT_SWITCH ) ? this.reverseDir( Input.dir4 ) : Input.dir4;
};

} )();
Now whenever switch 1 is set to true, the controls should be inverted (this code is untested, I haven't got MV installed at the moment, but the logic should be sound).

Change the value of INVERT_SWITCH to whatever switch number you'd like to use (so for switch #123 it would be var INVERT_SWITCH = 123;).
Wow! It's almost perfect!

What ended up happening was that any time I pressed a direction key the player moved in the opposite direction like I wanted (aaw yeah!)

An issue with the otherwise fantastic javascript (and this is my first attempt at working with it) is that whenever I'm NOT pressing a direction key then the player completely disappears from the map.

Do you have thoughts on how to keep the character around when a button input isn't being pressed?

I'm super excited that you were able to whip up something that worked so well :D So close to perfect!
 
Last edited:

Run

Towns Guard
Xy$
0.00
The disappearing characters is due to inverting the stationary position, which changes to the sprite to the next character down in the default character sheets(I assume there's none, or an empty one below you).
Using this if to ignore when the player is stationary should fix it.

JavaScript:
( function() {

var INVERT_SWITCH = 1;

Game_Player.prototype.getInputDirection = function() {
    if(Input.dir4 == 0){
        return 0;
    }
    return $gameSwitches.value( INVERT_SWITCH ) ? this.reverseDir( Input.dir4 ) : Input.dir4;
};

} )();
 

Xilefian

Adventurer
Xy$
0.00
Ah I forgot about this thread, thanks Run for pointing out the issue.

The fix can be merged into the ternary operation by adding Input.dir4 && at the start:
JavaScript:
( function() {

var INVERT_SWITCH = 1;

Game_Player.prototype.getInputDirection = function() {
    return Input.dir4 && $gameSwitches.value( INVERT_SWITCH ) ? this.reverseDir( Input.dir4 ) : Input.dir4;
};

} )();
In this case, it will only reverse direction if Input.dir4 is not zero (boolean check of Input.dir4 returns true of it is not zero). Otherwise, the Input.dir4 is returned (zero in the case of zero).
 
  • Like
Reactions: Run
Top