RPG Maker Forums

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!

Latest Threads

Latest Posts

Latest Profile Posts

On my journey of character rework: I had this character, she was meant to be just a princess that joins your party. And at long term she was just uninteresting... So I tweaked her to be a rebel agaisn't the royalty before meeting up with the party.

Quick tip for any other ametuer pixel artists! When trying to create a colour palette, enabling Antialiasing can speed up the process of creating different shades! Just place your lightest colour and your darkest colour next to each other, select both pixels, and stretch it out!
Revolutionizing the JRPG Industry: Knocking on Doors.

Take that, murderhobos.
Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.

Forum statistics

Threads
106,054
Messages
1,018,578
Members
137,843
Latest member
Betwixt000
Top