Moving Platforms

Greetings-

I am trying to script a moving platform, that the player must try to land on.

I have the following code:
Code:
var Imported = Imported || {};
Imported.PE_JumpMan = true;

var PE = PE || {};
PE.JumpMan = PE.JumpMan || {};

(function($){

    var JumpMan_Game_CharacterBase_jump = Game_CharacterBase.prototype.jump;
    Game_CharacterBase.prototype.jump = function(xPlus, yPlus) {

        let destX = $gamePlayer.x + xPlus;
        let destY = $gamePlayer.y + yPlus;

        let dest_event_id = $gameMap.eventIdXy(destX, destY);
        let dest_region_id = $gameMap.regionId(destX, destY);

        if (dest_event_id != 0) {
            if ($dataMap.events[dest_event_id].meta.platform == true) {
                JumpMan_Game_CharacterBase_jump.call(this, xPlus, yPlus);
                $gameSwitches.setValue(12, true);
            };
        } else if (dest_event_id === 0 && dest_region_id === 255) {
            JumpMan_Game_CharacterBase_jump.call(this, xPlus, yPlus);
            $gameSwitches.setValue(12, true);
            // $gameTemp.reserveCommonEvent(5);
            $gameSwitches.setValue(14,true);
        };

    };

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

        // input triggered is ok, call jump

        if (Input.isTriggered(`ok`) && Input.isPressed(`shift`)) {

            let jump_distance = (Input.isRepeated(`shift`)) ? 3 : 2;
            let xPlus = 0;
            let yPlus = 0;

            switch($gamePlayer.direction()) {
                case 2:
                    yPlus = jump_distance;
                    break;
                
                case 4:
                    xPlus = -(jump_distance);
                    break;

                case 6:
                    xPlus = jump_distance;
                    break;

                case 8:
                    yPlus = -(jump_distance);
                    break;
            };           
            
            $gamePlayer.jump(xPlus, yPlus);
        
        };

        if (Input.isTriggered() == false) {
            
            currX = $gamePlayer.x;
            currY = $gamePlayer.y;

            let curr_event_id = $gameMap.eventIdXy(currX, currY);

            if (curr_event_id != 0) {
                if ($dataMap.events[curr_event_id].meta.platform == true) {
                    $gameVariables.setValue(9, $gameMap.events(curr_event_id)._x);
                    $gameVariables.setValue(10, $gameMap.events(curr_event_id)._y);
                };
            };

        };


    
    };

}(PE.JumpMan));

which works with the Player and events that look like:
jumpman_platform_event.PNG


Unfortunately, this is what happens when the player lands on the platform:


  1. The player doesn't get towed by the platform.
  2. He gets thrown to the top left corner of the screen.

I know the problems lies with this:

JavaScript:
        if (Input.isTriggered() == false) {
            
            currX = $gamePlayer.x;
            currY = $gamePlayer.y;

            let curr_event_id = $gameMap.eventIdXy(currX, currY);

            if (curr_event_id != 0) {

                if ($dataMap.events[curr_event_id].meta.platform == true) {

                    $gameVariables.setValue(9, $gameMap.events(curr_event_id)._x);
                    $gameVariables.setValue(10, $gameMap.events(curr_event_id)._y);

                };

            };

        };

and in the event:

Code:
◆Transfer Player:{map_id} ({platform_x},{platform_y}) (Fade: None)

(Map ID is defined when the map is first loaded)

I am wondering if anybody has a better suggestion to do what I am trying to achieve?

I have tried searching Google and this forum itself, but cannot find any concrete leads.

TIA!
it looks nice to have this script in a puzzle map, question only is:
why a transfer player? while it doesn't really transfer to another map.
you also transfer to "this map id" while it can be avoided.

in my opinion, it need to jump and follow the platform rules, unless im mistaken?
it looks nice to have this script in a puzzle map, question only is:
why a transfer player? while it doesn't really transfer to another map.
you also transfer to "this map id" while it can be avoided.

in my opinion, it need to jump and follow the platform rules, unless im mistaken?

say what?
Extremely clunky... but as Benny Sings,er, sings, "Heeooo, I think I’ll get there..."

You want
$gamePlayer._x = $gameMap.event(1)._realX;
Or whatever event Id you're using for the platform.
It looks like you're setting their ._x properties to be equal, but that will make the player move at a different speed.
Have you tried this?
You want
$gamePlayer._x = $gameMap.event(1)._realX;
Or whatever event Id you're using for the platform.
It looks like you're setting their ._x properties to be equal, but that will make the player move at a different speed.
Have you tried this?

woo!



thank you @standardplayer
@aporokizzu Cool concept, nice to see what you've accomplished so far 🙂
Inspires me to make my own "lock player to events area" plugin though too.
This would be like yanfly's region restrictions but with events placed together (perhaps customization with notetags even too). That way you could have them walk/jump from platform to platform but if they aren't on a platform it would trigger script and maybe not let them pass or maybe they "fall off" and get relocated.
Added to the (very long) TODO list. 😉
@aporokizzu Cool concept, nice to see what you've accomplished so far 🙂
Inspires me to make my own "lock player to events area" plugin though too.
This would be like yanfly's region restrictions but with events placed together (perhaps customization with notetags even too). That way you could have them walk/jump from platform to platform but if they aren't on a platform it would trigger script and maybe not let them pass or maybe they "fall off" and get relocated.
Added to the (very long) TODO list. 😉

thanks @ct_bolt . the player falls right now when he lands in the wrong spot, i am still working on getting him to fall from the platform if he moves off it.

i also have to do minor things like add sound effects and jumping animations.

i am using note tags now to identify the platforms, and specify falling animations, definitely helps a lot in making the script more modular.

slowly but surely.

After three days, I think I finally got it.

Ohh, that's buttery smooth. I'd like to spread this on a lightly toasted slice of wheat bread and eat it with a glass of chocolate milk.
Good job XD Everything about this looks great
Ohh, that's buttery smooth. I'd like to spread this on a lightly toasted slice of wheat bread and eat it with a glass of chocolate milk.
Good job XD Everything about this looks great

couldn't have done it without your tip- thank you @standardplayer !
After three days, I think I finally got it.


Congrats! Awesome job with this ☺️ 👍
Congrats! Awesome job with this ☺️ 👍

thank you for the encouragement!
@aporokizzu ._realX and ._realY are what RPG Maker reads from while it's moving the sprites.
._x and ._y are the 'private' properties that the x and y getters actually read from.

And just for fun .scrolledX() and .scrolledY() will get you the x and y values relative to the screen's current position. So if you're standing on x:20, y:20, your scrolled X and scrolled Y would give you values relative to the portion of the map you can see on screen. (With normal screen settings, that means a y somewhere from 0 to 12 and an x somewhere from 0 to 16)

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.

Original thread: https://forums.rpgmakerweb.com/threads/moving-platforms.117553/