GM:S 1.4 [Help] Grid collision issue

Discussion in 'Programming' started by yvodlyn, Jan 11, 2019.

  1. yvodlyn

    yvodlyn Member

    Joined:
    Feb 3, 2017
    Posts:
    133
    Hello!
    My problem is when I put the box solid, everything work. However anything follow the grid. When I uncheck solid for the box, the player go through the box. I don't know what to do.
    Here a video to explain what's happen.


    here the code for the object grid, this object is for detecting collision between objects.

    Event_Create_1:
    var i,j;

    for (i = 0; i <= room_width div 32; i+=1){
    for (j = 0; j <= room_height div 32; j+=1){
    cells[i,j] = 0;
    }
    }
    with(oWallOne){
    oGrid.cells[x div 32, y div 32] = 1;
    instance_destroy();
    }

    This code is for the object solid:

    Event_create_1:
    ///Initialize Variables
    gridSize = 32;
    moveSpd = 2;
    isMoving = false;
    moveTimer = 0;
    hspd = 0;
    vspd = 0;

    Event_collide_to_player:

    if (isMoving == false){
    if (oPlayer.keyRight){
    if (oGrid.cells[x div 32 + 1, y div 32] == 0){
    isMoving = true;
    moveTimer = gridSize;
    hspd = moveSpd;
    vspd = 0;
    }
    }
    if (oPlayer.keyLeft){
    if (oGrid.cells[x div 32 - 1, y div 32] == 0){
    isMoving = true;
    moveTimer = gridSize;
    hspd = -moveSpd;
    vspd = 0;
    }
    }
    if (oPlayer.keyUp){
    if (oGrid.cells[x div 32, y div 32 -1] == 0){
    isMoving = true;
    moveTimer = gridSize;
    hspd = 0;
    vspd = -moveSpd;
    }
    }
    if (oPlayer.keyDown){
    if (oGrid.cells[x div 32, y div 32 +1] == 0){
    isMoving = true;
    moveTimer = gridSize;
    hspd = 0;
    vspd = moveSpd;
    }
    }
    }

    if (isMoving == true){
    x += hspd;
    y += vspd;
    moveTimer -= moveSpd;
    if (moveTimer == 0) isMoving = false;
    }
    thxt!
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,535
    What's the player's code? Because the pushable block is mvoing just fine. The player is the one not moving properly.

    Also, what solid does is set:
    x = xprevious;
    y = yprevious;
     
  3. The Video Gamester

    The Video Gamester Member

    Joined:
    Dec 2, 2016
    Posts:
    62
    My guess is that when the box is at the edge a few things happen
    1. Player moves and comes into contact with box
    2. Box checks if it can move which returns false
    3. Player is already in motion ends up in the same grid space as the box
    4. Every time the player moves it activates the box to move.

    Possible fix:
    Check if the player is going to hit the box
    If yes then check if the box has a valid space to move
    Allow player to move
    If no then player will not move
     
    yvodlyn likes this.
  4. The Video Gamester

    The Video Gamester Member

    Joined:
    Dec 2, 2016
    Posts:
    62
    Any luck? The game looks pretty cool. Was just wondering if the issue is resolved.
     
    yvodlyn likes this.
  5. yvodlyn

    yvodlyn Member

    Joined:
    Feb 3, 2017
    Posts:
    133
    Don't worry I find an other way to do it! the game is now available on play store
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice