SOLVED Grid UP collision, help please :), thank U

xNYARLx

Member
Hello :)
It's me again :)
I would like to make collisions on the GRID I am moving on, but only at the top. Left, right and down no. I did, but I can't move up and down on it at all. Someone help?

GML:
// CLIMB/GRID COLLISION
    var _collision = instance_place(x, y, obj_par_climb)
    if !(_collision == noone)
    {
        // grab the grid
        if (global.input_key_shift_pressed)
        {
            p_state = player_state.climb;
        }
       
        // move while on grid
        if (p_state == player_state.climb)
        {
            // prevent from jumping
            jump_count = 1; //0 to one jump from grid, 1 to 2 jumps (multi jump)
            grav = 0;
            jump_speed = 0;
            player_walk_running = false;
            move_speed = move_speed_default;
            y = _collision.y + _collision.sprite_height; //THERE IS COLLISION
               
            // player stop and fire
            if !(player_can_stopandfire)
            {
                move_speed = move_speed_grid;
                hsp = input_h * move_speed;
                vsp = input_v * move_speed;
            }
            else
            {
                move_speed = approach(move_speed, 0, move_speed_friction_default);
                vsp = approach(vsp, 0, move_speed_friction_default);
            }
           
            // leave grid [z pressed]
            if (global.input_key_z_pressed)
            {
                vsp = -5;
                grav = grav_default;
                jump_speed = jump_speed_default;
                move_speed = move_speed_default;
                p_state = player_state.idle;
            }
        }
        player_can_bounce = true;
    }
    else
    {
        // reset to default
        if (p_state == player_state.climb)
        {
            p_state = player_state.walk;
            grav = grav_default;
            jump_speed = jump_speed_default;
            move_speed = move_speed_default;
        }
    }
 

4i4in

Member
I would like to make collisions on the GRID
Define "on the grid" - mean that colision should be checked against square objects or after detecting colision player should get back to grid rigid position?
After detecting the coilsion relocate .x .y to the grid (passing over undesired directions like "down")?
 

xNYARLx

Member
Define "on the grid" - mean that colision should be checked against square objects or after detecting colision player should get back to grid rigid position?
After detecting the coilsion relocate .x .y to the grid (passing over undesired directions like "down")?
It means that I catch myself with the SHIFT button. And I'm walking on the 64x64 grid/net. Like a ladder but in all directions and I fall off it when I reach its end or I can jump off. The point is that there is no option that it will let the net go to its upper edge and fall everywhere else.
Bez tytułu.png
Bez tytułu.png
can fall if reach end of the grid/net
i moving on this green square in on all directions. wchen i reach end of green square i fall. I want fall in left side, right side, bottom side but DONT WANT FALL in TOP side.




I have to move in all directions, just don't fall off it when I reach the end at the top, but only!
Something like this:
y = _collision.y + _collision.sprite_height; //THERE IS COLLISION

but there i don't can go up and down
 
Last edited:

4i4in

Member
i moving on this green square in on all directions. wchen i reach end of green square i fall. I want fall in left side, right side, bottom side but DONT WANT FALL in TOP side.
make it a bit longer to the edge of the ladder?
 

xNYARLx

Member
yes. for ladder i make this:
x = _collision.x + _collision.sprite_width/2;

and player can olny go from down to up, and from up to down.

when i make this:
y = _collision.y + _collision.sprite_height/2;
player only can go from left to right and from right to left

but how make to go right, left, down, up but at the top edge dont fall from GRID/NET?

i dont know what CODE use
 

4i4in

Member
but how make to go right, left, down, up but at the top edge dont fall from GRID/NET?
Make a marker value that starage information of going on this grid and if it is true jump over the code causing fall.
I guess You did kind of gravity for platformer that allow character to fall. Reasonable.
Restrict this execution in case You are climbing on the grid. Execute the code causing fall only in case if not on ladder.
 

xNYARLx

Member
Make a marker value that starage information of going on this grid and if it is true jump over the code causing fall.
I guess You did kind of gravity for platformer that allow character to fall. Reasonable.
Restrict this execution in case You are climbing on the grid. Execute the code causing fall only in case if not on ladder.
The point is that it is supposed to fall, but only on the left, right and bottom. And at the top you want to stay on the net, go to the top of the net and not fall down or let the net go. Kind of like I gave SOLID up, it won't go down or go up higher.
 

xNYARLx

Member
Like this:
GML:
    // CLIMB/GRID COLLISION
    var _collision = instance_place(x, y, obj_par_climb)
    if !(_collision == noone)
    {
        // grab the grid
        if (global.input_key_shift_pressed)
        {
            p_state = player_state.climb;
        }
       
        // move while on grid
        if (p_state == player_state.climb)
        {
            // prevent from jumping
            jump_count = 1; //0 to one jump from grid, 1 to 2 jumps (multi jump)
            grav = 0;
            jump_speed = 0;
            player_walk_running = false;
            move_speed = move_speed_default;

if !place_meeting(x, y, obj_player)
    {
        // Inside a grid (must go down)
        while collision_point(x, y + 15, obj_climb, true, true)
        {
            if !collision_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, obj_player, false, true)
                y++
        }
    }
               
            // player stop and fire
            if !(player_can_stopandfire)
            {
                move_speed = move_speed_grid;
                hsp = input_h * move_speed;
                vsp = input_v * move_speed;
            }
            else
            {
                move_speed = approach(move_speed, 0, move_speed_friction_default);
                vsp = approach(vsp, 0, move_speed_friction_default);
            }
           
            // leave grid [z pressed]
            if (global.input_key_z_pressed)
            {
                vsp = -5;
                grav = grav_default;
                jump_speed = jump_speed_default;
                move_speed = move_speed_default;
                p_state = player_state.idle;
            }
        }
        player_can_bounce = true;
    }
    else
    {
        // reset to default
        if (p_state == player_state.climb)
        {
            p_state = player_state.walk;
            grav = grav_default;
            jump_speed = jump_speed_default;
            move_speed = move_speed_default;
        }
    }
 
Last edited:

4i4in

Member
The point is that it is supposed to fall, but only on the left, right and bottom. And at the top you want to stay on the net, go to the top of the net and not fall down or let the net go. Kind of like I gave SOLID up, it won't go down or go up higher.
I guess You set to many markers and then logic is confusing.

If You left green area fall is imminent? Whatever direction?
If You left from top - for sure You directly fall back on it.
If You are about to left from bottom - check if lefting and reposition it back.
If You moving horizontal - let it fall.
Something like that?
I imagine it should be something like in Super Mario?

I did that what You are trying to do same way as You do for 3d game decade ago and now I know it is not the best way. You are going to more and more exceptions.
Try to simplify definitions of what is legal set of values an check all sets if they are match.
 
Last edited:
Top