(Help) Tile map collisions

V

victinistar76

Guest
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;
 
P

Parker

Guest
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
 

TheouAegis

Member
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.
 

TheouAegis

Member
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
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.
 
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.
 
V

victinistar76

Guest
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.
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;
 
V

victinistar76

Guest
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
I am using invisible tiles for collision already.
 
V

victinistar76

Guest
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.
 

Slyddar

Member
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.
 
Top