Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

[GM7] Jumping with SSK Combo's Engine


BOB_ROX

Recommended Posts

Might be simple to some but I'm actually learning it at the moment, And I thought I'd ask here because I can't find any examples on "Jumping" at yoyo games which sucks. So I was wondering if anyone would like to tell me how?, And if its okay could you also make it so it can be added for a second jump please?

Thanks in Advance!

Link to comment
Share on other sites

The first thing I need to say is that the tutorial was designed to show users how to add combo systems into their existing games, it wasn't really designed to work the other way round. However you just want to know how to do jumping anyway, so I'll help you out.

The second thing. This is a LONG post, a step-by-step guide for variable jumping and decent collision which, hopefully, will be easy to understand.

  • CREATE OBJECT
    Make a new object: objParent_Solid. This object needs to be the parent for all solid tiles, so be sure you set them before testing.
  • ADD SCRIPT
    Add the following script in the Script folder and call it scrPlatform_Step:
    // ---- Clamp the speed values ----
    x_speed = max(min(x_speed, max_x_speed), -max_x_speed);
    y_speed += y_accel;
    y_speed = max(min(y_speed, max_y_speed*1.5), -max_y_speed);
    
    // ---- Y movement (down) ----
    if( y_speed > 0 )
        repeat( y_speed ) {
            if( !place_meeting(x,y+1,objParent_Solid) ) {
                y += 1;
                if( y_speed > 1 && ground == 1 ) {
                    y_speed = 1;
                    ground  = 0;
                }
            }
            else if( place_meeting(x,y+1,objParent_Solid) ) {
                y_speed = 0;
                y_accel = 0;
                ground  = 1;
            }
        }
    
    // ---- Y movement (up) ----
    if( y_speed < 0 )
        repeat( -y_speed ) {
            if( !place_meeting(x, y-1, objParent_Solid) ) {
                y       -= 1;
                ground  =  0;
            }
            else y_speed =  0;
        }
    while( place_meeting(x,y,objParent_Solid) && ground == 1 )y -= 1;
    
    // ---- X movement (right) ----
    if( x_speed > 0 )
        repeat( x_speed ) {
            if( !place_meeting(x+1, y, objParent_Solid) ) {
                x += 1;
                if( !place_meeting(x,y+1,objParent_Solid) && ground == 1 )y += 1;
            }
            else x_speed = 0;
        }
    
    // ---- X movement (left) ----
    if( x_speed < 0 )
        repeat( -x_speed ) {
            if( !place_meeting(x-1, y, objParent_Solid) ) {
                x -= 1;
                if( !place_meeting(x,y+1,objParent_Solid) && ground == 1 )y += 1;
            }
            else x_speed = 0;
        }
    

    This code is the main bulk of the platforming. First it makes sure that the speed of the player never exceeds the top speed. Then it checks for walls and floors in every direction in a very simple way. The character's mask sprite might need to be adjusted for the best results.

  • GO TO OBJECT
    Now to focus on the player object. Go to obj_sonic and we'll start editing the events we need to get jumping to work.
  • CREATE EVENT
    We need to add a few new variables to get a jump system working. Change the code...
    x_speed = 0; max_x_speed = 8;

    ...to this

    x_speed     = 0;   y_speed     = 0;
    max_x_speed = 8;   max_y_speed = 8;
    
    y_accel     = 1/2; y_gravity   = 1/2; // these sort out gravity
    jump_timer  = 0;   jump_power  = 7;   // these sort out jumping
    jump_count  = 0;   // checks for double jump
    ground      = 1;   // this checks if the player is on the ground

    And add the following code to the controls part at the bottom

    key_up = ord('W'); // or whatever key you want


  • STEP EVENT
    Since the y_accel variable is set to 0 when you hit the ground, it needs to be reset every step otherwise we get no gravity.
    y_accel = y_gravity;

    Next, we need to add the actual jumping code. Add this at the bottom of the Movement Input code:

    // ---- Double Jump ----
    if( ground == 0 && keyboard_check_pressed(key_up) && jump_count == 0 ) {
        jump_count = 1;
        y_speed    = -jump_power;
    }
    // ---- Start Jump ----
    if( ground == 1 && keyboard_check_pressed(key_up) ) {
        // sound effect here
        y_speed    = -jump_power;
        jump_timer = 0;
        ground     = 0;
        jump_count = 0;
    }
    // ---- Variable Jump ----
    if( !keyboard_check(key_up) ) {
        jump_timer = 30;
    }
    if( state == "normal" && y_speed < 0 && jump_timer <= 30 && keyboard_check(key_up) ) {
        y_speed  -= (jump_power/30);
        jump_timer += 1;
    }

    Remember this is variable jumping, the longer you hold the button the higher you jump.

  • BEGIN STEP EVENT
    Delete it. You won't need it once we finish re-doing the End Step Event.
  • END STEP EVENT
    Add this new code before every other action in this event to call the platforming script above:
    scrPlatform_Step();

    You will need to work on the animation code afterwards. Thankfully, you can use the ground variable in an if statement to check if the player is on the ground or air and adjust the animations accordingly.

And that is it! If you need anything else explaining in more detail, just reply.

EDIT: The jumping code has been edited to eliminate an infinite jumping error.

Link to comment
Share on other sites

This will be because of that silly "recovery" variable I used.

Get rid of the following line in the Step Event's last code box:

if( attack_index = 0 && recovery > 0 )exit;

You can also remove the recovery variable entirely since it is useless.

I don't really know why I even had an artificial recovery timer, since it gave the impression to many that the controls were unresponsive and stiff... which is not good in a fighting game.

  • Like 1
Link to comment
Share on other sites

Thanks, Now all I gotta do is the animation thing. Oh and by the way, what would you suggest be the best grappling hook example/engine thats conpatible with it?, or do I just choose any I find?.

EDIT:

Actually scratch that the thanks part I got another bug with him jumping more than twice.

Link to comment
Share on other sites

I got another bug with him jumping more than twice.

Just make some kind of variable that increases every time he jumps, and when he jumps when that variable is maxed out, he can't jump. Then when he hits the ground it resets.

Link to comment
Share on other sites

Dont want to sound stupid but I dont exactly know how to do that..

Im also having trouble with the animation of him jumping because I have it in the animation code at the bottem but it wont play.

if( jump_power = 7 )
{ if( sprite_index = spr_jump ){ sprite_index = spr_jump; image_index = -1; } image_speed = 0.5; exit; }
if( jump_count = 2 )
{ if( sprite_index != spr_jump2 ){ sprite_index = spr_jump2; image_index = -1; } image_speed = 0.5; exit; }[/CODE]

The reason why both varibles are different is because I didnt know which one Im supposed to use.

Link to comment
Share on other sites

Sorry about the error. Completely replace the jump code in obj_sonic's Step Event with this (

I will also edit the first response with the fixed double-jump code):

// ---- Double Jump ----
if( ground == 0 && keyboard_check_pressed(key_up) && jump_count == 0 ) {
    jump_count = 1;
    y_speed    = -jump_power;
}
// ---- Start Jump ----
if( ground == 1 && keyboard_check_pressed(key_up) ) {
    // sound effect here
    y_speed    = -jump_power;
    jump_timer = 0;
    ground     = 0;
    jump_count = 0;
}
// ---- Variable Jump ----
if( !keyboard_check(key_up) ) {
    jump_timer = 30;
}
if( state == "normal" && y_speed < 0 && jump_timer <= 30 && keyboard_check(key_up) ) {
    y_speed  -= (jump_power/30);
    jump_timer += 1;
}

As for the animation error, you're going about setting the conditions a bit wrong. Use the "ground" variable to check for jumps (example, if ground == 0 the player is in the air). To apply this to the code, put this at the top of your animation code:

if( ground == 0 ) {
    // player is not double jump and rising
    if( jump_count == 0 && y_speed < 0 )
    { if( sprite_index != spr_jump ){ sprite_index = spr_jump; image_index = 0; } image_speed = 0.5; exit; }

    // player is not double jump and falling
    if( jump_count == 0 && y_speed >= 0 )
    { if( sprite_index != spr_fall ){ sprite_index = spr_fall; image_index = 0; } image_speed = 0.5; exit; }

    // player is double jumping
    if( jump_count == 1 )
    { if( sprite_index != spr_jump2 ){ sprite_index = spr_jump2; image_index = 0; } image_speed = 0.5; exit; }
}

Notice that I've added an extra condition and sprite for FALLING too, so make sure you add a falling sprite called "spr_fall".

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...