Jumping

From Game Editor

Jump to: navigation, search

Jumping is definitely one of the most asked questions, and it is also one of the best ways to learn how to script. Since jumping requires variables, It is one of the first things that most gameEditor users will need script for. There are methods outside of script editor, but none of them are suggested. Those methods, such as MoveTo, would be used in special cases. To make an actor jump, you need to be familiar with variables.


First create a variable called jump or something similar. Depending on the game, you might want to call the variable On_Ground, or some derivative. The variables hold the same information, but sometimes On_Ground can be more useful. Anyway, after you have created the jump variable, add the following code to your jump key down event.


Player -> KeyDown (jump, disabled) -> Script Editor

if(jump>0)
{
    jump--;
    yvelocity=-10;
}


This code checks if the actor's jump count is higher than zero, and if so, lowers jump by one, and sets the yvelocity of the actor to -10. There are other forms of jumping, one that decreases yvelocity by 10, instead of setting it to -10. This would achieve the effect of irregular jumps, based on falling. The number 10 can be changed to also have different jumps.


To make this code work, we need to actually set jump, as on startup it is set to zero. To do this, add in your collision event, which should be placed in script editor, with repeat enabled, the following code.

jump=1;

In games that have double jump and higher, you would set jump to 2 or more, assuming that all jumps will have the same effect. There are more advanced ways to do jumping, if you are doing multi-typed jumps, but this is one of the most basic jumping methods, and in this case is usually the first scripting done by new gameEditor users.