SOLVED The last problem with jumping when player fall, please help

xNYARLx

Member
Hello.
The last problem/bug what i have in game is with jumps when player is fall

I have made that when I fall I may jump once. It works fine except for one drawback when the obj_solid is so low that I can touch it with my head. Then I can jump endlessly, because I keep jumping when falling (if onground).

GML:
    if !onground
    {
        if !once2 //to only do it once
    {
    jump_count =1;
    once2 = true;
    }
    }
    else
                if onground
                {
                    once2 = false;
                }
 
Last edited:

xNYARLx

Member
I figured it out, but I don't know how to do it.

if (vsp > 0)

??

or

var _collision = instance_place(x, y, obj_player);
if !(_collision == noone)
{
with (_collision)
{
if (_collision.vsp > 0)
{
there rest?
}

??

GML:
    var _collision = instance_place(x, y, obj_player);
    if !(_collision == noone)
    {
                    with (_collision)
    {
        if (_collision.vsp > 0)
        {
            if !onground
    {
        if !once2
    {
    jump_count =1;
    once2 = true;
    }
    }
        }
    }
    }
    else
                if onground
                {
                    once2 = false;
                }
                }
 
Code:
var _collision = instance_place(x, y+1, obj_player);
Should fix it. Y increments downwards, so y+1 is checking below the instance, rather than exactly on the sprite (note: this may require a little more code to settle the player on the ground properly as there will be a pixel gap when it lands, due to the check being a pixel below the player).
 

xNYARLx

Member
This my solid vertical collision:
GML:
// SOLID VERTICAL COLLISION
    var _collision = instance_place(x, y+sign(vsp)*3+vsp, obj_par_solid);
    if (_collision != noone)
    {
        if (_collision.solid_type == 0)
        {
            repeat (abs(vsp) + 1)
            {
                if (place_meeting(x, y + sign(vsp), obj_par_solid)) break;
                y += sign(vsp);
            }
            vsp = 0;
           
            onground = true;
        }
       
        if (_collision.solid_type == 1)
        {
            if (vsp > 0)
            {
                // activate fall-through platforms
                if (global.input_key_fall_pressed)
                {
                    player_can_fallplatform = true;
                }
               
                // collision
                if (!place_meeting(x, y, obj_par_solid))
                {
                    if !(player_can_fallplatform && !variable_instance_exists(_collision, "one_way"))
                    {
                        repeat (abs(vsp) + 1)
                        {
                            if (place_meeting(x, y + sign(vsp), obj_par_solid)) break;
                            y += sign(vsp);
                        }
                        vsp = 0;
                   
                        onground = true;
                    }
                }
                else
                {
                    onground = false;
                    player_can_fallplatform = false;
                }
            }
            else
            {
                onground = false;
            }
        }
    }
    else
    {
        onground = false;
    }
    // update vertical movement
    y += vsp;
And this i make and don't want work :(

GML:
    var _collision = instance_place(x, y+1, obj_player);
    if !(_collision == noone)
    {
                    with (_collision)
    {
        if (_collision.vsp > 0)
        {
            if !onground
    {
        if !once2
    {
    jump_count =1;
    once2 = true;
    }
    }
        }
    }
    }
    else
                if onground
                {
                    once2 = false;
                }
 

xNYARLx

Member
I make this on this way:
GML:
    if !onground
    {
        if !once2
    {
    jump_count =1;
    once2 = true;
    }
    }
    else
                if onground && p_state = player_state.idle or onground && p_state = player_state.walk or onground && p_state = player_state.swim or onground && p_state = player_state.climb or onground && p_state = player_state.ladder or onground && p_state = player_state.slide
                {
                    once2 = false;
                }
 
Top