#ledge/edge jump code.

1 messages · Page 1 of 1 (latest)

thorny stirrup
#

i'm trying to do a code where if the player is bellow a wall/object, in the ledge/edge and it's jumps, it's push he some pixels away for it to jump normaly.

here two of my main codes, moviment and collision.

//collision
function collision(){
    
    repeat(abs(vel_x)){
    
        if (place_meeting(x + sign(vel_x), y, Obj_collider)){
        
            if (!place_meeting(x + sign(vel_x), y - 1, Obj_collider)) y--;
            else {if (!place_meeting(x + sign(vel_x), y + 1, Obj_collider)) && 
                (place_meeting(x + sign(vel_x), y + 2, Obj_collider)) y++;}
        }
    
        if (place_meeting(x + sign(vel_x), y, Obj_collider)) {
        
                vel_x = 0;
                break;
        }
            else {x += sign(vel_x)}
        
    } 

    repeat(abs(vel_y)){
        
        if (place_meeting(x, y + sign(vel_y), Obj_collider)){
            
            vel_y = 0;
            break;
        }
        else {y += sign(vel_y)}
    }

}

(the moviment one is on the comments)

#
free_moviment = function(){
    
    if (input_check("left") || input_check("right")){
        move_dir = (input_check("right") - input_check("left"));
        move_spd = lerp(move_spd, spd_max, .2)
    }
        else{move_spd = lerp(move_spd, spd_min, .4)}
    
    if (can_move > 0) {can_move = lerp(can_move, 0, .6)}
    
    if (can_move = 0) {vel_x = move_dir * move_spd;}
    
    if (vel_x != 0) {x_scale = sign(vel_x)}
    
    if (input_check_pressed("jump")) && (coyotetime > 0) && (jump_count < max_jumps){
        jump_count++;
    
        jump_timer = jumphold_frames;
    }

    if (!input_check("jump")){jump_timer = lerp(jump_timer, 0, .99)}

    if(jump_timer > 0){
        
        coyotetime = 0;
        vel_y = 0;
        vel_y -= jump_spd;
    
        jump_timer--;
    }

    if (input_check_pressed("jump")) buffertime = buffer_max;

    if (buffertime > 0){
        
        buffertime--;
    
        if (on_ground()){
            
            vel_y -= jump_spd;
            buffertime = 0;
        }
    }
        
    if (!on_ground()) && (instance_place(x + 1, y - 1, Obj_collider)) {vel_x -= 4;}
    else if  (!on_ground()) && (instance_place(x - 1, y - 1, Obj_collider))    {vel_x += 4}
    
    if (on_ground()) {jump_count = 0;}
        else {vel_y += grav;}
        
    if (on_wall()) && (!on_ground()){
    
        if (vel_y > 1) {vel_y = 1;}
        
        if (input_check_pressed("jump")){
        
            vel_y = 0;
            vel_y -= jump_spd * 1.60;
            can_move = 1;
            jump_timer--;
            vel_x -= 6 * x_scale;
        
        }
    }
    
    image_xscale = x_scale;
    image_yscale = y_scale;

}
hot marsh
#

Modern 2d mario games have a similar concept, generally speaking the simplest solution is to check 4 points above the playe'rs head. if only one of point collides with a block then we can puch the player over.

For instance if the 4th line was the only one which collided with a block/ceilding, then we would move the player roughly 2 pixels to the left.

Though if the 2 or more points are colliding with a ceiling then we are planned to hit the ceiling and we can trigger the block hit effect.

You can fine tune the how much forgiveness you want by changing how far apart the inner two are from the outer two. Usually speaking you want to make these roughly the same space apart as the distance you can already travel per frame, so there isnt much snapping visually.

thorny stirrup
#

how exacly i can apply it?

#

i'm in like to beginer to medium level

#

so i don't know how to translate that concerpt to code

hot marsh
#

here is a rough example with some configurable values which you can change to fine tune how forgiving it is.

var _adjustment_spacing = move_speed; //how far from the outer eadge to check the inner collisions, roughly your move speed, but can be any number
var _height_dist = 2; //how many pixels above the player's head to check, this will want to be > or = to your jump speed

var _left_outer = collision_point(bbox_left, bbox_top, obj_solid, false, true);
var _left_inner = collision_point(bbox_left+_adjustment_spacing, bbox_top-_height_dist, obj_solid, false, true);
if (_left_outer) && (!_left_inner) { //if we barely touched a block on the left
    //move right
}
var _right_outer = collision_point(bbox_right, bbox_top, obj_solid, false, true);
var _right_inner = collision_point(bbox_right-_adjustment_spacing, bbox_top-_height_dist, obj_solid, false, true);
if (_right_outer) && (!_right_inner) { //if we barely touched a block on the right
    //move left
}

remember to change the collisions to a collision system which works best for you.

thorny stirrup
#

i did the edits and didn't work

thorny stirrup
#

im being dumb?

hot marsh
#

well you're adjusting the velocity, not the player's x

#

also line 147 and 148, these should just be static unchanging numbers, so like the max_speed and jump_max_spd

thorny stirrup
#

like this?

hot marsh
#

does it work?

thorny stirrup
#

hum...

hot marsh
#

try x -= _adjustment_spacing

#

which is the same thing as x = x-_adjustment_spacing

thorny stirrup
#

it's gets this issue where when works, the x and stuff don't stop

#

so i lost control of my character and it's got stock inside a block

#

you want to see all variebles i create to you see if helps?

#

to undestand better what i can do to fix

#

because i did everything u said

hot marsh
#

are you only checking for this when you are jumping?

thorny stirrup
#

...

#

i forgot to put if(!on_ground)...

#

that's it, right?

#

i think worked

#

but i still got stuck in the when i jump in the edge

#

mostly in the left side

#

oooh. okay

#

when i do the edge thing and press the opsite direction, i got stuck inside the block

thorny stirrup
#

Maybe if I use the can_move variable, it can help. What do you think?