San_AnalogMove.js - Direction issue

● ARCHIVED · READ-ONLY
Started by Eliaquim 6 posts View original ↗
  1. Hi people!

    I'm trying to solve a bug in this plugin of pixel movement/diagonal. But without success, I need some help :kaodes:

    When I go Up(8) + Right(6) the player turns his direction to the right, but stills go up.
    When I go Down(2) + Left(6) the player turns his direction to the left, but stills go down.
    When I go Right(6) + Down(2) the player turns his direction to down, but stills go right.
    When I go Left(4) + Up(8) the player turns his direction to up, but stills go left.

    This is strange because the player can walk into a door that is in front of him while facing right for example.

    See a video:
    Spoiler


    I'm pretty sure that the problem is in this part(besides my tries, I cannot make it to work properly):

    code line 321
    Code:
    // ラジアン方向を8方向に変換
    CharacterMover.radToDir8 = function(radian) {
        var piDiv8 = Math.PI / 8.0;
        return (
            radian < piDiv8 * -7.0 ? 4 :
            radian < piDiv8 * -5.0 ? 7 :
            radian < piDiv8 * -3.0 ? 8 :
            radian < piDiv8 * -1.0 ? 9 :
            radian < piDiv8 *  1.0 ? 6 :
            radian < piDiv8 *  3.0 ? 3 :
            radian < piDiv8 *  5.0 ? 2 :
            radian < piDiv8 *  7.0 ? 1 :
            4
        );
    };
    
    // 8方向をラジアン方向に変換
    CharacterMover.dir8ToRad = function(dir8) {
        var x = (dir8 % 3 === 0 ? 1.0 : (dir8 % 3 === 1 ? -1.0 : 0.0));
        var y = (dir8 / 3 <=  1 ? 1.0 : (dir8 / 3 >   2 ? -1.0 : 0.0));
        return Math.atan2(y, x);
    };
    
    // ラジアン方向を4方向に変換
    CharacterMover.radToDir4 = function(radian) {
        var piDiv4 = Math.PI / 4.0;
        return (
            radian < piDiv4 * -3.0 ? 4 :
            radian < piDiv4 * -1.0 ? 8 :
            radian < piDiv4 *  1.0 ? 6 :
            radian < piDiv4 *  3.0 ? 2 :
            4
        );
    };
    
    // 4方向をラジアン方向に変換
    CharacterMover.dir4ToRad = function(dir4) {
        return this.dir8ToRad(dir4);
    };
    
    // 8方向を4方向に変換
    CharacterMover.dir8ToDir4 = function(dir8, dir4) {
        return (
            dir8 % 2 === 0 ? dir8 :
            dir8 === 7 ? (dir4 === 6 ? 8 : 4) :
            dir8 === 9 ? (dir4 === 2 ? 6 : 8) :
            dir8 === 3 ? (dir4 === 4 ? 2 : 6) :
            dir8 === 1 ? (dir4 === 8 ? 4 : 2) :
            2
        );
    };

    Thanks!
  2. I wonder if it has something to do with the order of the directions in the plugin or something.

    I know in unity if I put my walking animations in this order:

    DOWN
    LEFT
    RIGHT
    UP

    Then when I walk diagonally DOWN the DOWN animation is prioritized because DOWN is ahead of LEFT and RIGHT in the blend tree order.
    And when I walk diagonally UP the LEFT or RIGHT animation is prioritized because both LEFT and RIGHT are ahead of UP in the blend tree order.

    RM doesn't seem to have an order it seems to go based on whichever direction you were pressing first but maybe the plugin makes an order? Sorry, probably not helping much at all, but hopefully this can get figured out.
  3. @bazrat

    [[[ EDIT 2 ]]]
    Well.. this is hard =/
    But at least I've found the code that would be the key to solve this:

    Code:
    CharacterMover.radToDir4 = function(radian) {
        //var piDiv4 = Math.PI / 4.0;
        return (
            radian < Math.PI / 4.0 * -1.0 ? 4 :
            radian < Math.PI / 4.0 * -3.0 ? 8 :
            radian < Math.PI / 4.0 *  1.0 ? 6 :
            radian < Math.PI / 4.0 *  3.0 ? 2 :
            4
        );  
    };

    The return value from this function is the direction that the player will be facing.
    So if return:
    4 = Right
    6 = Left
    8 = Up
    2 = Down.

    I've tried a way to make this function return this number dynamically according to the button that player presses. But no results.
    I've tried to use these codes below to store the current input and the last input before the current one.

    Code:
    Input._currentState
    Input._latestButton
    Input._previousState

    So if the player presses 'down' and while 'down' is still pressed he press 'left' or 'right', the return value will be 2.
    If the player presses 'left' and while 'left' is still pressed he press 'up' or 'down', the return value will be 4.
    etc...
    But doesn't work too.
    I tried that too(with and without "else if"):

    code
    Code:
    CharacterMover.radToDir4 = function(radian) {
        var sandir;
        var firstbutton;
        if(Input.isPressed("down")) {
            firstbutton = "baixo";
            if(Input.isPressed("left") && firstbutton == "arrowdown") {
            sandir = 2;
        }
        if(Input.isPressed("right") && firstbutton == "arrowdown") {
            sandir = 2;
        }
        } else if(Input.isPressed("left")) {
            firstbutton = "arrowleft";
        if(Input.isPressed("down") && firstbutton == "arrowleft") {
            sandir = 4;
        }
        if(Input.isPressed("up") && firstbutton == "arrowleft") {
            sandir = 4;
        }
        } else if(Input.isPressed("right")) {
            firstbutton = "arrowright";
        if(Input.isPressed("down") && firstbutton == "arrowright") {
            sandir = 6;
        }
        if(Input.isPressed("up") && firstbutton == "arrowright") {
            sandir = 6;
        }
        } else if(Input.isPressed("up")) {
            firstbutton = "arrowup";
        if(Input.isPressed("left") && firstbutton == "arrowup") {
            sandir = 8;
        }
        if(Input.isPressed("right") && firstbutton == "arrowup") {
            sandir = 8;
        }
        }
        return sandir;
    };

    The old version doesn't have this issue and manages the direction another way...

    old version code part
    Code:
        Game_AnalogMove.prototype.dir8ToDir4 = function(dir8) {
            if (dir8 % 2 === 0) {
                return dir8;
            }
            switch (this._direction) {
            case 8:
                switch (dir8) {
                case 3:  return 6;
                case 1:  return 4;
                default: return 8;
                }
            case 6:
                switch (dir8) {
                case 1:  return 2;
                case 7:  return 8;
                default: return 6;
                }
            case 2:
                switch (dir8) {
                case 7:  return 4;
                case 9:  return 6;
                default: return 2;
                }
            case 4:
                switch (dir8) {
                case 9:  return 8;
                case 3:  return 2;
                default: return 4;
                }
            }
            return undefined;
        };

    Get some rest now :kaophew:




    edit 1
    [[EDIT 1 ]]Manage to fix, at least, the down move! *____*

    Change this:
    Code:
        var piDiv4 = Math.PI / 4.0;
        return (
            radian < piDiv4 * -3.0 ? 4 :
            radian < piDiv4 * -1.0 ? 8 :
            radian < piDiv4 *  1.0 ? 6 :
            radian < piDiv4 *  3.0 ? 2 :
            4
        );

    Let's see if I can fix the other direction too!

    to this:
    Code:
    CharacterMover.radToDir4 = function(radian) {
        //var piDiv4 = Math.PI / 4.0;
        return (
            radian < Math.PI / 4.0 * -3.0 ? 4 :
            radian < Math.PI / 4.0 * -1.0 ? 8 :
            radian < Math.PI / 4.0 *  1.0 ? 6 :
            radian < Math.PI / 3.0 *  3.0 ? 2 :
            4
        );
    };

    Old
    I don't think so.
    Because if you put down and after you put right, the character still walks diagonal lower right, but facing down.

    But if I put Down and after put left, the character walks diagonal lower left but facing left.

    I think there is a way trying to apply the same logic that the code used for "down + right" in the "down + left".
    But can't find it :/
  4. Hi there! I notice that events in your map don't shake like they do in mine. Are you using the latest version of this plugin 3.15? That may help. Of course, then you run into the issue of events shaking when you move diagonally...
  5. Made the fix! You can find it here.
  6. 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.