Moving Platforms

Status
Not open for further replies.

aporokizzu

anti-kumbaya
Member
Joined
Jan 14, 2020
Messages
16
Reaction score
20
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
1,160
Reaction score
379
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
Member
Joined
Jan 14, 2020
Messages
16
Reaction score
20
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
Member
Joined
Jan 14, 2020
Messages
16
Reaction score
20
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
538
Reaction score
2,451
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
665
Reaction score
195
First Language
Javascript
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. ;)
 

aporokizzu

anti-kumbaya
Member
Joined
Jan 14, 2020
Messages
16
Reaction score
20
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
538
Reaction score
2,451
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
538
Reaction score
2,451
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
6,534
Reaction score
5,553
First Language
English
Primarily Uses
RMMV

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 Profile Posts

Here's a sample of some pixel edits I made.

Maybe for use as sidewalks.
If there are any mods or admins online, could you please see about the re-translation pages for RPG Maker MV? They are all down :rsad:
Werewolf cons: you lose control of yourself once a month and could accidentally kill your friends. Vampire cons: no garlic bread. The choice is simple. Werewolf for sure.
2 huge market drops in 2 days. So glad I sold my non-dividend stocks about 2 weeks ago. And if the dividend ones drop heavily, hey more cheap stocks for me!
My tutorial is live! It covers using Yanfly's weapon unleash to replace the basic attack skill with a more dynamic version depending on which weapon type the actor has equipped. It also includes how to import a custom function used to generate a random number within supplied minimum and maximum values, used in the replaced skills, to give weapons a set damage range.

Forum statistics

Threads
94,524
Messages
921,600
Members
124,377
Latest member
Darkyyy
Top