In this tutorial you will learn…|
Another use for parallel systems
How to make a player jump with a certain button
How to make your system allow the player to jump over objects
Hi there! Welcome to my eigth event system tutorial. In this tutorial I'll be showing you how to make a system whereby the main character will jump when the player
presses a certain button on their keyboard. So, let's get started. For this tutorial, you will need:
ê A common event
ê An automatic switch (see my Automatic Switches if you're not sure about this.)
Right. Firstly, as always, get yourself some working space - a nice blank map. Then, head straight into the database and go over to the common events tab. Create
a new common event, and call it 'Jumping' or something that will remind you of what it does. Then, in the top section where the conditions are, set the trigger to
parallel, and the condition to a new switch called 'Jumping' being on. Your page should look like this…
Now, although we've set the condition to being this new switch, we haven't actually got a way to turn it on yet. This is where the automatic switch comes in. Take
a note of the number switch that you're using - mine is number 19. Memorise your number, and then open the script editor. If you haven't used automatic switches
before, don't worry; it's not difficult at all.
Once you've opened the script editor, scroll down the script list until you find the script called Scene_Title. Click on this. Now, scroll down until about line
142, where you'll see the text $scene = Scene_Map.new. Underneath this, we're going to add the following code…
$game_switches = true
Note: If you've already used automatic switches and already have the $game_map.refresh method here, then you don't need to add it again.
After adding your automatic switch, your code screen should look like this…
Note: Bear in mind that this switch will only be turned on if you start a new game. If you want this switch to be turned on every time you load a game, go
to my Automatic Switches tutorial and scroll down to find out how to add a switch to the loading process.
So far, so good! Now that we've sorted out how we're going to activate the common event, we need to add in the commands. We're going to do this by using conditional
branches to decide whether we're pressing the jump button (more on this in a moment), and if we are, whether we're pressing it at the same time as a directional
button. If we are, it will adjust the jump command so that we jump in the direction of the button that we're pressing.
So, firstly, we need to decide which button we're going to use as our jump button. There is an easy way to see which button on the keyboard corresponds to which
in-game button - playtest your game, and, when it starts up, press F1 on your keyboard. You'll get this box…
This is the options dialogue. I'll go into more detail about these options in a different tutorial, but at the moment, we're just interested in the 'Keyboard' tab
at the top of the window. Click on this tab, and you'll get something like this…
Now, this window shows us which in-game buttons are connected to which keys on our keyboard. Obviously space and enter are the same - and we know what that button
does. Also, we know what the escape button does. So, that leaves us with the rest of the buttons to pick from. In my example, I am going to use button A as the
jump button, which is assaigned to Shift and to Z on the keyboard. Once you've chosen which keyboard button you'd like as your jump button, take note of its letter
and close down the options box and quit your playtest.
Now we know which button we want to use, we can go back to our common event. In your event commands section, insert a conditional branch, and head to the fourth
page. At the bottom, you'll see the condition 'Button… is being pressed.' This is the command we want. Go to the drop-down and select your button's letter
from the menu. For me, it'll be button A. Your conditional branch box will now look like this…
Obviously your button letter will be whichever button you chose - but for me, it's button A.Before you click OK on the bottom of the conditional branch box,
just uncheck the 'Set handling when conditions do not apply;' we don't need this. Then press OK. Once you've got your first branch done, we need to input the
In your conditional branch, input another conditional branch with a button condition, but this time, set it to the Down directional button. This time, make sure
that you leave the box at the bottom checked. Then press OK. Now we have a branch for when jump and down are pressed at the same time. Your commands should be
looking something like this…
Now, in the else section of that conditional branch, add another branch, exactly the same as the previous one, but this time with the Left directionary button
selected as the condition. See where we're going with this? Some good ol' embedded conditional branching! Keep going, the next one with the Right button, and the
final one with the Up button. Normally we wouldn't bother with the final button, because if it isn't the other directions, it can only be the last remaining one.
However, in this system, it's quite a nice feature if, when there are no directional buttons being pressed and the jump button is pressed, the player jumps in
place. (This is optional - if you only want the player to jump when there is a direction, you can leave the Up button's conditional branch blank, or
uncheck the Up button's 'Set handling' box.)
Okay, your final set of commands should look like this…
Right, now just the jumping commands to do. In the first branch, the Down one, insert a Set Move Route command, and in this, insert a jump. Now, we want the player
to jump downwards, so we need to leave 0 in the X-drection box, and put 2 in the Y-direction box. Shouldn't that be negative 2? I hear you ask. I agree, it is an
awkward system, but in RMXP, if you want to move downwards, you actually increase the Y-direction value. Confusing, huh? (The reason we're using 2 and not
1 in the jump box will become clear later on.)
Your jump box should look like this for the Down direction…
Press OK at that, and then press OK at the Set Move Route box. Now, don't forget to add in a Wait for Move's Completion command! Once you've done that, you can
put in the jumps for the other branches. For Left, it will be X: 2, Y: 0, for Right, X: -2, Y: 0, and Up, X: 0, Y: -2. In the last else section of the Up branch,
we can input the jump for if there are no directional buttons being pressed. This is just a jump with coordinates X: 0, Y: 0, making the player jump in place.
Okay! Now the top half of your commands should be like this…
You can see all the different jumping directions. And now we're done! You can test out your system. Don't forget - if you only used the new game automatic switch
(in the Scene_Title script), you'll have to start a new game to get it to work.
Pretty cool, huh? The only thing with this system is that you have to be pressing the directional button before you press the jump button to get the player to jump
in a direction, but that's a limitation of RMXP, I'm afraid. Now, if you put an impassable tile in the way of the player, and walk up to it, you'll find that you
can jump over it. This is why we used 2 in the jump box, rather than 1 - if we'd used 1, the player wouldn't have been able to jump over anything. It's a pretty
neat system, don't you think? The only little glitch in this is that the player can jump 'through' trees, which isn't quite so realistic. If you want to stop
this, you'll have to use terrain tags and a little extra eventing to prevent jumping 'through' objects. I intend to write a mini tutorial on this, so keep
Well, that's it - you've been taught how to jump! My next tutorial will be on more advanced event systems. See you there!
:: << Skip Back to Tutorial VI ::
:: Home ::
:: Next Tutorial >> ::