Moving Platforms

Status
Not open for further replies.

aporokizzu

anti-kumbaya
Veteran
Joined
Jan 14, 2020
Messages
59
Reaction score
89
First Language
english
Primarily Uses
RMMV
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!
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,895
Reaction score
1,029
First Language
Dutch
Primarily Uses
RMMV
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?
 

aporokizzu

anti-kumbaya
Veteran
Joined
Jan 14, 2020
Messages
59
Reaction score
89
First Language
english
Primarily Uses
RMMV
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?
 

aporokizzu

anti-kumbaya
Veteran
Joined
Jan 14, 2020
Messages
59
Reaction score
89
First Language
english
Primarily Uses
RMMV
Extremely clunky... but as Benny Sings,er, sings, "Heeooo, I think I’ll get there..."

 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
698
Reaction score
3,450
First Language
English
Primarily Uses
N/A
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?
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
520
First Language
Javascript
Primarily Uses
RMMZ
@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

anti-kumbaya
Veteran
Joined
Jan 14, 2020
Messages
59
Reaction score
89
First Language
english
Primarily Uses
RMMV
@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.

 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
698
Reaction score
3,450
First Language
English
Primarily Uses
N/A
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
 

standardplayer

Keeper of Kitties
Veteran
Joined
Apr 6, 2016
Messages
698
Reaction score
3,450
First Language
English
Primarily Uses
N/A
@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)
 

Touchfuzzy

Rantagonist
Staff member
Lead Eagle
Joined
Feb 28, 2012
Messages
7,295
Reaction score
8,904
First Language
English
Primarily Uses
RMMZ

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,570
Latest member
fgfhdfg
Top