• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

HELP! Looping through collision list with tags

TomOmNom

Member
New Somewhat New to GM, sorry.
So I've been messing around in GMS 2.3 and have employed the use of tags in a collision system, where I can search for any asset with the tag "wall" and collide with it. Unfortunately, this has somewhat buggy results.
GML:
#region Controls
controls = {
    up : keyboard_check(vk_up),
    down : keyboard_check(vk_down),
    right : keyboard_check(vk_right),
    left : keyboard_check(vk_left)
}
#endregion Controls

hInput = (controls.right - controls.left);
vInput = (controls.down - controls.up);

if hInput = 0 && vInput = 0
{
hsp = 0;
vsp = 0;
} else {
dir = point_direction(0,0,hInput,vInput);
hsp = lengthdir_x(stats.msp, dir);
vsp = lengthdir_y(stats.msp, dir);
}

wallArray = tag_get_assets("wall");
for (i = 0; i < array_length(wallArray);i++)
{
collisionTarget = asset_get_index(wallArray[i]);

if place_meeting(x+hsp,y,collisionTarget)
{
    while !place_meeting(x+sign(hsp),y,collisionTarget) x += sign(hsp);
    hsp = 0;
}

if place_meeting(x,y+vsp,collisionTarget)
{
    while !place_meeting(x,y+sign(vsp),collisionTarget) y += sign(vsp);
    vsp = 0;
}

}
x += hsp;
y += vsp;
This works pretty dang well, but when colliding with corners it sometimes breaks. I'm not sure how to fix this, is it due to the 8 directional movement part of the code? That's the only explanation I see, and the rest of the code seems to work well without the 8 directional movement integration.

I've attached an image of how the player and wall objects often collide at corners.
 

Attachments

Top