• 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!

Collision Issue

H

Hollywoo

Guest
I have a game I'm working on with 8-direction movement. This is the current code for movement:

Code:
///Input | Movement | Shooting

//Input for movement
up = keyboard_check(ord('W'));
left = keyboard_check(ord('A'));
down = keyboard_check(ord('S'));
right = keyboard_check(ord('D'));

xDirection = right - left;
yDirection = down - up;

dir = point_direction(0, 0, xDirection, yDirection);

//Movement and Collisions
if (up || left || right || down)
{
    if !place_meeting(x + lengthdir_x(walkSpeed, dir), y, Solid)
    {
        x += lengthdir_x(walkSpeed, dir);
    }
    else
    {
        while (!place_meeting(x + sign(xDirection), y, Solid))
        {
            x += sign(xDirection);
        }
    }
  
    if !place_meeting(x, y + lengthdir_y(walkSpeed, dir), Solid)
    {
            y += lengthdir_y(walkSpeed, dir);
    }
    else
    {
        while (!place_meeting(x, y+sign(yDirection), Solid))
        {
            y += sign(yDirection);
        }
    }
}
This allows for movement in the chosen direction without diagonal movement being faster than normal horizontal and vertical movement.

My issue is, the collision detection method I would normally use, of just checking which way I'm moving and, if the distance is less than the rate at which I'd be moving that way, moving up to the object and stopping, doesn't seem to be working right. Instead I stop a bit away from it, and if I slide along the edge trying to push toward it, I'll inch closer and then get stuck.

Any suggestions for what I can put in those "else" sections to fix my collisions?
 
Top