Eli_FixAnalogMove

● ARCHIVED · READ-ONLY
Started by Eliaquim 13 posts View original ↗
  1. [embedded media]

    Author Eliaquim
    *No longer supported*
    Requirements

    SAN_AnalogMove.js


    Introduction
    Originally the plugin San_AnalogMove.js has a problem with the direction of diagonal movement:
    • When going Up + Right the player turns his direction to the right, but stills go up.
    • When going Down + Left the player turns his direction to the left, but stills go down.
    • When going Right + Down the player turns his direction to down, but stills go right.
    • When going Left + Up the player turns his direction to up, but stills go left.
    This can causes issues like the player to open doors that are triggered via player touch while he is facing another direction rather than the door.

    Features
    Fix direction problem with SAN_AnalogMove.js

    How to Use
    It's plug and play. Just make sure to put below SAN_AnalogMove.

    Eli_FixAnalogMove.js
    JavaScript:
    //============================================================================
    // Eli_FixAnalogMove.js
    //============================================================================
    
    /*:
    @plugindesc v1.2 - Fix direction problem with San_AnalogMove.js
    @author Eliaquim or Rakuen Zero
    
    
    @help
    
    
    ==============================================================================
    Introduction
    ==============================================================================
    
    Originally the plugin San_AnalogMove.js has a problem with the direction of
    diagonal movement:
    
    When going Up + Right the player turns his direction to the right, but
    stills go up.
    When going Down + Left the player turns his direction to the left, but stills
    go down.
    When going Right + Down the player turns his direction to down, but stills
    go right.
    When going Left + Up the player turns his direction to up, but stills go
    left.
    
    This can causes issues like the player to open doors that are triggered via
    player touch while he is facing another direction rather than the door.
    
    ==============================================================================
    Features
    ==============================================================================
    
    Fix direction problem with SAN_AnalogMove.js
    
    ==============================================================================
    How to use
    ==============================================================================
    
    Just make sure to put below SAN_AnalogMove.
    In the plugin parameter "Three Buttons Stop Player" leave it as "false" if
    you want to use the default behavior of Rm Mv for character movement by
    pressing these three directional keys:
    up-left-right.
    low-up-right.
    Set it to "true" if you want the player to stop moving by pressing this
    combination of three directional buttons.
    
    ==============================================================================
    Terms of Use
    ==============================================================================
    
    1. It is mandatory to give the credits to Eliaquim or Rakuen Zero in the
    credits section of your game.
    2. It can be used in free and commercial games.
    3. Do not sell or say that you made this plugin.
    4. Do not redistribute this plugin. Instead, give this link to the download:
    
    ==============================================================================
    Special thanks and considerations
    ==============================================================================
    
    The plugin is free. However, consider donating if possible.
    This can help me with small expenses and motivation! Working with games
    in Brazil is very difficult. But don't feel obligated. I hope my small
    contribution is also a fuel of hope for you to continue to make your games!
    Thank you! Happy Rpg Making!
    
    ==============================================================================
    Contact
    ==============================================================================
    
    Facebook - https://www.facebook.com/nascmento.eliaquim
    RM Web - https://forums.rpgmakerweb.com/index.php?members/eliaquim.123037/
    Centro Rpg Maker - https://centrorpg.com/index.php?action=profile
    
    ==============================================================================
    Updatelog - Log de atualizações
    ==============================================================================
    Version 1.3 - 01/02/2020
    - Changes in the code for better readability.
    Version 1.2 - 10/01/2019
    - Inserted plugin parameter as a workaround for another problem of direction
    and movement with the player, when three directional buttons are pressed.
    - Updated help file!
    Thanks to ShadowDragon.
    Version 1.1 - 09/29/2019
    - Fix the direction problem of the followers.
    Version 1.0 - 09/27/2019
    - Plugin release!
    
    @param Three Buttons Stop Player
    @type boolean
    @on Yes
    @off No
    @desc Stop player movement when 3 directional buttons are pressed at same time.
    @default false
    
    
    
    */
    
    /*:pt
    @plugindesc v1.2 - Conserta um bug de direção que havia no plugin SAN_AnalogMove.
    @author Eliaquim or Rakuen Zero
    
    @help
    
    ==============================================================================
    Introdução
    ==============================================================================
    
    Originalmente o plugin San_AnalogMove.js tem um problema com a direção do
    player quando anda na diagonal:
    
    Se apertar cima + direita, o jogador se direciona para direita, mas continua
    andando para cima.
    Se apertar baixo + esquerda, o jogador se direciona para esquerda, mas
    continua andando para baixo.
    Se apertar para direita + baixo, o jogador se direciona para baixo, mas
    continua andando para direita.
    Se apertar esquerda + cima, o jogador se direciona para cima, mas continua
    andando para esquerda.
    
    Isso faz com que o jogador entre em uma porta que está acima dele enquanto
    olha para a direita, por exemplo.
    
    ==============================================================================
    Funcionalidades
    ==============================================================================
    
    Conserta um bug de direção que havia no plugin SAN_AnalogMove.
    
    ==============================================================================
    Como usar
    ==============================================================================
    
    Instale no plugin manager abaixo do SAN_AnalogMove.
    No parâmetro de plugin "Three Buttons Stop Player" deixe-o como "false" se
    deseja usar o comportamento padrão do Rm Mv para o movimento do personagem
    ao pressionar essas três teclas direcionais:
    - cima-esquerda-direita.
    - baixo-cima-direita.
    Coloque-o para "true" se desejar que o jogador pare de se mover ao apertar
    essa combinação de três botões direcionais.
    
    ==============================================================================
    Termos de uso
    ==============================================================================
    
    1. É obrigatório dar os créditos para Eliaquim ou Rakuen Zero na seção
    de créditos do seu jogo.
    2. Pode ser usado em jogos gratuitos e comerciais.
    3. Não venda e nem diga que foi você que fez esse plugin.
    4. Não redistribua esse plugin. Ao invés disso, dê este link para o download:
    
    ==============================================================================
    Contato
    ==============================================================================
    
    Facebook - https://www.facebook.com/rakuenzero/
    Itch io - https://rakuenzero.itch.io/
    RM Web - https://forums.rpgmakerweb.com/index.php?members/eliaquim.123037/
    Centro Rpg Maker - https://centrorpg.com/index.php?action=profile
    
    ==============================================================================
    Log de atualizações
    ==============================================================================
    Versão 1.3 - 02/01/2020
    - Modificações no código para melhor leitura.
    Versão 1.2 - 01/10/2019
    - Inserido um parâmetro de plugin para corrigir outro problema de direção e
    movimento do player quando três botões direcionais são pressionados ao mesmo
    tempo.
    - Atualização do arquivo de ajuda.
    Agradecimentos a ShadowDragon.
    Versão 1.1 - 29/09/2019
    - Corrigido o problema de direção com os seguidores.
    Versão 1.0 - 27/09/2019
    - Plugin lançado!
    
    @param Three Buttons Stop Player
    @text Três direcionais apertados param o jogador
    @type boolean
    @on Sim
    @off Não
    @desc Impede o jogador de se mover quando três botões direcionais são apertados ao mesmo tempo.
    @default false
    
    */
    
    "use strict";
    
    var Imported = Imported || {};
    Imported.Eli_FixAnalogMove = true;
    
    var Eli = Eli || {};
    Eli.FAM = Eli.FAM || {};
    
    if(Imported.SAN_AnalogMove) {
    
    Eli.Parameters = PluginManager.parameters('Eli_FixAnalogMove');
    Eli.Param = Eli.Param || {};
    
    Eli.Param.FixAnalogMove = {
        ThreeButtonsStopPlayer: JSON.parse(Eli.Parameters['Three Buttons Stop Player'])
    };
    
    // Overwrite default function
    CharacterMover.radToDir4 = function(radian) {
    };
    
    // Overwrite default function
    CharacterMover.dir8ToDir4 = function(dir8, dir4) {
    };
    
    function fixNormalDir() {
        const playerDir = $gamePlayer.direction();
            if (playerDir === 8 && Input.isPressed("down")) {
                return $gamePlayer.setDirection(2);
            }
            if (playerDir === 6 && Input.isPressed("left")) {
                return $gamePlayer.setDirection(4);
            }
            if (playerDir === 4 && Input.isPressed("right")) {
                return $gamePlayer.setDirection(6);
            }
            if (playerDir === 2 && Input.isPressed("up")) {
                return $gamePlayer.setDirection(8);
            }
    };
    
    function fixDiagonalDir() {
        const playerDir = $gamePlayer.direction();
            if(Input.isPressed("down") && (playerDir === 4 || playerDir === 6)) {       
                return $gamePlayer.setDirection(2);
            }
            if(Input.isPressed("left") && (playerDir === 2 || playerDir === 8)) {       
                return $gamePlayer.setDirection(4);
            }
            if(Input.isPressed("right") && (playerDir === 2 || playerDir === 8)) {       
                return $gamePlayer.setDirection(6);
            }
            if(Input.isPressed("up") && (playerDir === 4 || playerDir === 6)) {       
                return $gamePlayer.setDirection(8);
            }
    };
    
    // Fix direction of the player if 3 directional buttons are pressed.
    function fixthreeinputs() {
        if (Input.isPressed("up") && Input.isPressed("right") && Input.isPressed("left")) {
            return $gamePlayer.setDirection(8);
        }
        if (Input.isPressed("up") && Input.isPressed("right") && Input.isPressed("down")) {
            return $gamePlayer.setDirection(6);
        }
    };
    
    // Player stop moving when 3 directional buttons are pressed.
    // Alias
    Eli.FAM.Game_Player_canMove = Game_Player.prototype.canMove;
        Game_Player.prototype.canMove = function() {
            if(Eli.Param.FixAnalogMove.ThreeButtonsStopPlayer) {
                if (Input.isPressed("up") && Input.isPressed("right") && (Input.isPressed("left") || Input.isPressed("down"))) {
                    return false;
                }
                if (Input.isPressed("down") && Input.isPressed("right") && Input.isPressed("left")) {
                    return false;
                }
            }
        return Eli.FAM.Game_Player_canMove.call(this);
            
    };
    
    function fixFollowerDir(follower) {
        const playerDir = $gamePlayer.direction();
        const playerRealX = $gamePlayer._realX;
        const playerRealY = $gamePlayer._realY;
        const followerRealX = $gamePlayer.followers().followers()[follower]._realX;
        const followerRealY = $gamePlayer.followers().followers()[follower]._realY;
            if(playerDir === 6  && playerRealX > followerRealX) {
                return $gamePlayer.followers().followers()[follower].setDirection(6);
            }
            if(playerDir === 4 && playerRealX < followerRealX) {
                return $gamePlayer.followers().followers()[follower].setDirection(4);
            }
            if(playerDir === 2 && playerRealY > followerRealY) {
                return $gamePlayer.followers().followers()[follower].setDirection(2);
            }
            if(playerDir === 8 && playerRealY < followerRealY) {
                return $gamePlayer.followers().followers()[follower].setDirection(8);
            }
    }
    
    // Overwrite default function
    FollowerMover.prototype.updateCharacter = function() {
        const precedingCharacter = this.character().precedingCharacter();
        const preChaPosVec = precedingCharacter.posVec();
        const relPosVec = preChaPosVec.sub2(this._posVec);
        this.character().setPosVec(this._posVec);
        this.character().setDirVec(relPosVec);
    };
    
    // Alias
    Eli.FAM.CharacterMover_update = CharacterMover.prototype.update;
        CharacterMover.prototype.update = function() {
            Eli.FAM.CharacterMover_update.call(this);
            const flw = [0, 1, 2];
            fixNormalDir();
            fixDiagonalDir();
            if(!Eli.Param.FixAnalogMove.ThreeButtonsStopPlayer) {
                fixthreeinputs();
            }
            // else {
            //     Eli.FAM.Game_Player_canMove();
            // }
            flw.forEach(fixFollowerDir);
    };
    
    } else {
        throw new Error('San_AnalogMove.js is missing!');
    };


    Credit and Thanks

    No need to credit me.
    For the original one, give credits to Sanshiro.
    It can be used in free and commercial games.
    Do not sell or say that you made this plugin.

    Thanks for Sanshiro for this amazing pixel movement plugin!:kaoluv:

    Update Log
    Spoiler
    Version 1.3 - 01/02/2020
    - Changes in the code for better readability.
    Version 1.2 - 10/01/2019
    - Inserted plugin parameter as a workaround for another problem of direction
    and movement with the player, when three directional buttons are pressed.
    - Updated help file!
    Thanks to ShadowDragon.
    Version 1.1 - 09/29/2019
    - Fix the direction problem of the followers.
    Version 1.0 - 09/27/2019
    - Plugin release!
  2. Approving this thread (and nice video BTW!), but looking through your plugin - are you sure this will work for all cases? Like, if that door were to the right of the player instead of above the player (after walking up-right using diagonal movement), would the player still be able to trigger it? Admittedly I'm not familiar with Sanshiro's script or its alleged flaw, but my understanding of your code is that it is still setting the player's direction to one cardinal direction based on which buttons they had been pressing (and returning from the method before it can evaluate the other cases), and I feel like the player's intention may be one of any two directions they were pressing.
  3. If I understand you correctly, yes, the player still be able to trigger it!

    Basically what I want to do is the engine to memorize the first direction the player walks.
    For example, if he press down then the playeand while moving down the
    Wavelength said:
    Approving this thread (and nice video BTW!), but looking through your plugin - are you sure this will work for all cases? Like, if that door were to the right of the player instead of above the player (after walking up-right using diagonal movement), would the player still be able to trigger it? Admittedly I'm not familiar with Sanshiro's script or its alleged flaw, but my understanding of your code is that it is still setting the player's direction to one cardinal direction based on which buttons they had been pressing (and returning from the method before it can evaluate the other cases), and I feel like the player's intention may be one of any two directions they were pressing.
    Hi, thank you!

    Yes, it would still be able to trigger it!
    I'm not sure if I understand you correctly, but I will give a try:

    My intention was that there was a predominant direction in the player's movements.
    Based on the first direction the player started walking.
    So if he started walking down, he can walk (left || right) + down which will keep facing down.

    The problem with the original plugin was that if it went down-left it would turn left(and not down).
    But if he walked down-right it would turn down.
    And all the other diagonal directions had this problem.
  4. Oh, I see now! So this wouldn't fix the scenario where a player started walking right and then turned up in order to reach the door, but it would fix it as long as they started walking up first, and it also stops the player's direction from turning like crazy while moving primarily in one direction, which is pretty nifty on its own.
  5. Awesome Eli, you figured it out xD

    :MV1:
  6. Updated to version 1.1!
    - Fixed a problem with direction of the followers too.
  7. @Eliaquim when checking your plugin, on "function fixNormalDir()" if player dir === 4, it doesn't have a return to 6,
    while the other 3 (8, 6, 2) has a return, shouldn't 4 has a return as well? or do I miss something here?

    EDIT:
    there seems to be something off when look "left" or "right" and press both left and right and going doing, it look left or right and slide down.

    but it doesn't happen when looking in other direction when pressing 3 buttons, while it go diagonal, It only happen when left, right and pressing down.

    otherwise. nice plugin.
  8. ShadowDragon said:
    @Eliaquim when checking your plugin, on "function fixNormalDir()" if player dir === 4, it doesn't have a return to 6,
    while the other 3 (8, 6, 2) has a return, shouldn't 4 has a return as well? or do I miss something here?

    EDIT 1
    there seems to be something off when look "left" or "right" and press both left and right and going doing, it look left or right and slide down.

    but it doesn't happen when looking in other direction when pressing 3 buttons, while it go diagonal, It only happen when left, right and pressing down.

    otherwise. nice plugin.
    EDIT 1
    Oh, thanks! I will check it out and give a reply here!

    EDIT 2
    "function fixNormalDir()" if player dir === 4, it doesn't have a return to 6,
    while the other 3 (8, 6, 2) has a return, shouldn't 4 has a return as well? or do I miss something here?
    there seems to be something off when look "left" or "right" and press both left and right and going doing, it look left or right and slide down.
    Fixed that! Thanks, ^^

    but it doesn't happen when looking in other direction when pressing 3 buttons, while it go diagonal, It only happen when left, right and pressing down.
    This is a very strange behavior. I realized that we can push three buttons at the same time.
    But for each combination, the player performs a nonstandard movement, as you said.
    Pressing down + right + up moves the player to the right looking down.
    If you press left + right + up, the player moves up looking up.
    But if we press down + left + right, the player continues to move diagonally.

    1 - I made a few attempts and got a quick fix. With that, at least the player looks in the direction in which it is moving.

    2 - Another fix I found is that pressing 3 directional at the same time will not move the player. It will be stopped until you release one of the buttons. I didn't find this beautiful, but at least it's a more standardized solution.

    I will make more tests later and see what is the best option.

    I hope Sanshiro notices my attempts and sympathizes with a mere mortal like me hahahaahaha.:hswt:

    EDIT 3:
    Well, it seems that this is behavior from the Core codes of Rm Mv itself.
    I tried to remove both my fix plugin and the analog one, and the same thing happens, but not with diagonal. I can't find a way to solve this.
    Rm Mv lets you press up-left-right.
    But he doesn't let you press down-left-right
    Put this at a parallel event and you will see.
    Spoiler
    Code:
    ◆If:Script:Input.isPressed("down") && Input.isPressed("right") && Input.isPressed("left")
      ◆Text:None, Window, Bottom
      :    :Player keep moving.
      ◆
    :End
    ◆If:Script:Input.isPressed("up") && Input.isPressed("right") && Input.isPressed("left")
      ◆Text:None, Window, Bottom
      :    :Player stop moving.
      ◆
    :End

    So I will put the fix direction as a standard behavior in the plugin when you press those three buttons. At least the player will face the direction that he is walking.
    But I will put a parameter that if it's set to true, the player will stop moving if these 3 directional buttons are pressed at the same time. If it's return false, the plugin will work with the standard behavior.

    With that said:
    Updated to version 1.2!
    - Inserted plugin parameter as a workaround for another problem of direction
    and movement with the player, when three directional buttons are pressed.
    - Updated Help file.
  9. I test it out, but found the following (with param OFF)

    when going left, down, right, it goes straight down)

    when param ON (LOCK if player press 3 buttons)

    up, left, right (lock player)
    down + up, lock player, same for up + down

    No lock when pressing left, up, down, up, left down, down, left, up,
    which walk diagnoally to the left.

    Idk how though, but I'm thinking, this wont be an easy fix,
    while looking at teh code added, do you need to make any direction available to walk correctly
    or make it lock, when left, down, up is pressed? or right, up, left, etc?

    the lock work nicely when "right" is pressed though with 3 buttons pressed.
    but while my coding isn't top yet, do you need && and || for button combinations? (just a guess though)

    EDIT:
    I might know a nice fix if you are able too.

    for example:
    if UP + LEFT is pressed, walk upper left (but if you press the 3rd button to it
    like (RIGHT or DOWN) it will be ignored)

    if UP + RIGHT is press, walk upper right (ignore the other 2)

    and this on every direction, so 3 or 4 buttons cant be pressed and return
    to the last 2 directions pressed.

    Only if its possible though, so the lock param would be not needed anymore
    and you have the prefect fix if you can accomplish it ^^.
  10. @ShadowDragon hi!
    Thanks for giving it a try.
    I'm already aware of these problems. But I can't solve it.
    The best way to work around in this plugin is to have some way to detect the last input pressed before the current one.
    But I can't do that(yet). So I made the plugin this way, with if statements to check the pressed buttons.
    I can't make the character lock when, for example, press the 3 buttons: left, up, down. Because the Rm Mv doesn't let me press these 3 buttons at the same time(he don't recognize those three inputs).
    Like I demonstrate here(if you put that in a parallel event, you will see):

    Code:
    ◆If:Script:Input.isPressed("down") && Input.isPressed("right") && Input.isPressed("left")
      ◆Text:None, Window, Bottom
      :    :Player keep moving.
      ◆
    :End
    ◆If:Script:Input.isPressed("up") && Input.isPressed("right") && Input.isPressed("left")
      ◆Text:None, Window, Bottom
      :    :Player stop moving.
      ◆
    :End

    Even if I figure a way out for this, it will mess with the default behavior of the Core codes from rm mv itself. And I don't wanna do that because it can create other problems with other plugins that I can't imagine. Also, I don't know if it is a bug from core codes, or it's a logic behind that which I don't understand xD.

    So the only thing I do is at least, fix the direction of the player when all these buttons are pressed at the same time. And for those who think it is weird, if these buttons are pressed at the same time, it can lock the player.

    Maybe in the future when my skills in coding are better, I can make a fix to it. But now, I can't.
    Alternatively, if you want to use a pixel movement, you can try HalfMove.js from triacontanne. It's not pixel movement, but it is smooth ^^
  11. I might use that in compare wit hthe other 2 plugins for behind objects and smooth stairs.
    the setup for that is complicated but its awesome when done.

    I try to find a way to fix this neet plugin, so only 2 buttons can reconized, and ignores the 3rd and 4th button press.
    Or if you find out how. Than you have the nicest fix for this pixel movement.

    Ping me if you got a way, or I ping you if I might have a way.
  12. I will no longer support this plugin. I removed it from itch io and attached it to the first post.
  13. Closed at OP'S request