(Help) Tile map collisions

Discussion in 'Programming' started by victinistar76, Dec 4, 2018.

Tags:
  1. victinistar76

    victinistar76 Member

    Joined:
    Nov 30, 2018
    Posts:
    4
    I followed two different tutorials and it came out with the same outcome. The collision does not work properly and will not work with the way it is set up. Here is my code:
    Code:
    var bbox_side;
    //Vertical Movement
    if (vsp > 0) bbox_side = bbox_bottom; else bbox_side = bbox_top;
    if (tilemap_get_at_pixel(tilemap, bbox_side+vspeed, bbox_left) != 0) || (tilemap_get_at_pixel(tilemap, bbox_side+vspeed, bbox_bottom) != 0)
    {
        if (vsp > 0) y = y- (y mod 64) + 63 - (bbox_bottom - y);
        else y = y - (y mod 64) - (bbox_top - y);
        vsp = 0
    }
    y += vsp;
    
    //Horizantal Movement
    
    if (hsp > 0) bbox_side = bbox_right; else bbox_side = bbox_left;
    if (tilemap_get_at_pixel(tilemap, bbox_side+hspeed, bbox_top) != 0) || (tilemap_get_at_pixel(tilemap, bbox_side+hspeed, bbox_right) != 0)
    {
        if (hsp > 0) x = x- (x mod 64) + 63 - (bbox_right - x);
        else x= x - (x mod 64) - (bbox_left - x);
        hsp = 0
    }
    x += hsp;
    
    
    
    
    
     
  2. Parker

    Parker Member

    Joined:
    Sep 24, 2018
    Posts:
    21
    I believe that the reason that Game Maker lets you use tiles is because they are optimized. Those tiles don't check collision and I am pretty sure you can't run code through them. I have used tile based collisions before but the collision code isn't in the tile its self. You have to create an invisible object above those tiles and that object will do collision. The tiles shouldn't do anything. I may be wrong I don't use tiles that much in Game Maker Studio
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    The problem is you are swapping your arguments around in your tile collision code. In one code you were checking for the vertical speed as argument one, and the other code your checking for horizontal speed in argument one. Argument one is horizontal, argument two is vertical.
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    in studio one and legacy version styles or crap, not very well implemented. But you can still do code without objects for colliding with them. You never needed objects to begin with, it was just the lazy Game Maker way. Studio 2, tiles were overhauled and now you can code directly with them, you can even run code from them so to speak. The collision methods are still pretty much the same, though, you just use different functions in studio 2 than you would and the older ones.
     
  5. SnortySnoopy

    SnortySnoopy Member

    Joined:
    Apr 25, 2018
    Posts:
    47
    You should re-watch Shaun Spalding's tutorial that you saw. There are lines of codes that you missed. Namely the ones related to calculating the vsp and hsp value which is taken from the object movement that will be checked against the bbox sides.
     
  6. victinistar76

    victinistar76 Member

    Joined:
    Nov 30, 2018
    Posts:
    4
    you mean this?
    Code:
    key_right = keyboard_check(vk_right);
    key_left = keyboard_check(vk_left);
    key_up = keyboard_check(vk_up);
    key_down = keyboard_check(vk_down);
    
    hsp = (key_right - key_left) * 5;
    vsp = (key_down- key_up) * 5;
    
     
  7. victinistar76

    victinistar76 Member

    Joined:
    Nov 30, 2018
    Posts:
    4
    I am using invisible tiles for collision already.
     
  8. victinistar76

    victinistar76 Member

    Joined:
    Nov 30, 2018
    Posts:
    4
    Let me explain more. When i run my program, it will glitch out in places without collision and will touch collision and jump far away from it.
     
  9. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    585
    Are you using whole numbers with your tile collisions? I've found you need to store the fractional part of hsp and vsp before the collision code, using frac(), but also reapply it again each step before removing it, to ensure it's still included.
     
  10. Parker

    Parker Member

    Joined:
    Sep 24, 2018
    Posts:
    21
    You should try using invisible object collisions, I always will use invisible object collisions because tile collisions get confusing.
     

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