RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[RM2K/3] Basic Platforming: Jump Attacks

0 Members and 1 Guest are viewing this topic.

Level 84
puking up frothing vitriolic sarcastic spittle
(This should work equally well in RM2K, RM2K3, RMXP and RMVX!)

In order to make basic, jumping attacks you need to be able to do a handful of different things.

1) Keep track of where enemies are on the map (their x and y coordinates).
2) Keep track of where the hero is on the map (same coordinates as above).
3) Know how to make the hero jump (obviously).
4) Know when the hero has landed on an enemy (again, obviously).


So, first of all you need to create 2 variables for every enemy you have on a map. One to store their x coordinate and one to store their y coordinate. Basically, two variables called:

- Enemy 1 X Coord
- Enemy 1 Y Coord

These need to be constantly updated using a "Parallel Process" event on the map the enemies are on - this should be set somewhere the hero can't reach. The code should look something like this:

Code: [Select]
Variable Operation: [xxxx: Enemy 1 X Coord] Set, Enemy 1 X Coord
Variable Operation: [xxxx: Enemy 1 Y Coord] Set, Enemy 1 Y Coord
Wait 1 Frame

This will keep track of where the enemy is. You obviously need to do this for every enemy on that map. Keep them all in the same event to save on space.


You also need to add something that keeps track of the hero. This is basically exactly the same:

Code: [Select]
Variable Operation: [xxxx: Hero X Coord] Set, Hero 1 X Coord
Variable Operation: [xxxx: Hero Y Coord] Set, Hero 1 Y Coord
Wait 1 Frame

This should be kept in the same event as the enemy tracking.

Now, as the Hero can't normally land on the same spot as the monsters (as they are all on the same level) there is no way that these coordinates can ever be the same. So we are going to use these to check when the Hero lands on top of the monsters. First, though, we need to make the hero jump.


You will need another variable for this section. Call it "Button Pressed".

There is an event command called "Key Input Processing" (or something similar. It depends which maker you are in). This will let you store the value of a button pressed to a variable - store it to the "Button Pressed" variable you just made - and each button has its own number.

Aside: You'll have to work out which button has which value yourself because I don't know how this works in each maker specifically. It shouldn't be very difficult as this event command has a list of possible buttons. In RM2K you only get to use SHIFT, but in later makers you have a wider range of choices for your jump button.

After doing this, you can then check if the button you specified is being pressed by having a "Fork Condition" (or whatever your maker calls them - "Conditional Branch" is the other name I know for this) that checks the value of the "Button Pressed" variable. If the variable equals the number of the button you want then trigger a jump, if not then let the cycle repeat over again.

What does this mean in terms of "code"? Create a Parallel Process on your map that looks like this:

Code: [Select]
Change Variable: "Jumping?" V:[XXXX] Set = 0
Input Processing: Store [i]{button}[/i] To Variable: "Jumping?" V:[XXXX]
If Variable V:[XXXX] = [i]{the value of the button you want goes here}[/i] then
   Move Hero: Start Phasing, Start Jump, Move Foward, End Jump, End Phasing.
End Case
Wait 1 Frame

This will need to be pasted on to every map you want the hero jumping on.

For this to work properly, you need to make sure that the "Input Processing" is NOT set to "Wait Until Key Pressed" or your player won't be able to move. You also need to make sure that the movement is set to "Ignore Impossible Actions" so that the game won't jam when the player tries to jump onto an inaccessible tile.

You'll also need to turn this off during cutscenes. To do this, make it so the event has a second page triggered by a switch called "Cutscenes On" and leave this second page blank. At the start of a cutscene, turn this switch on and at the end of this cutscene turn this switch off. This will stop people jumping around during your cutscenes and messing them up.


Now all you need is to check if the hero is on the same space as any of the monsters. If he is then he has just jumped on them and they should be killed. This should also be done in a new event on the map set to be a "Parallel Process". This only needs to be done on maps that contain enemies:

Code: [Select]
If Hero Coord X = Enemy 1 Coord X Then
   If Hero Coord Y = Enemy 1 Coord Y Then
  <Show the death animation for the monster here. This is up to you.>
Wait 1 Frame

Repeat this "Fork Condition" for every single enemy on the map (this should be obvious!)

Hope this makes sense to everyone! If it doesn't then just drop me a PM and I can try expaining whatever is giving you problems.