• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows Game freeze upon colliding with a corner.

a_lone_

Member
I've spent a while getting my movement code with proper acceleration and smooth collisions to work with as a little code as possible, and while I was doing so my ideas changed a lot and the code still has remnants of old organization. At some point in the process, I discovered that whenever I made a pixel-perfect collision with a corner, the game window would freeze and have to be closed using the IDE's stop button, or a task manager end task. I thought I'd fix this probably later, but I still have not been able to locate its source.

Code:
//get input
yin = (keyboard_check(ord("S")) - keyboard_check(ord("W")));
xin = (keyboard_check(ord("A")) - keyboard_check(ord("D")));
inDir = point_direction(0,0,xin,yin);

//round small velocities to 0
if abs(vx) < 0.3 {
    vx = 0;
}
if abs(vy) < 0.3 {
    vy = 0;
}

//friction
vx -= kfrict*vx;
vy -= kfrict*vy;

//acceleration
ax = (((dcos(inDir))*abs(xin)*movespeed)/mass);
ay = (((dsin(inDir))*abs(yin)*movespeed)/mass);

aMag = point_distance(x,y,x+ax,y+ay);
aDir = point_direction(x,y,x+ax,y+ay);

if abs(vy+ay) <= abs(yin*vmax) and abs(vx+ax) <= abs(xin*vmax) {
    vy += ay;
    vx += ax;
} else if abs(vy+ay) <= abs(yin*vmax) {
    vy += ay;
} else if abs(vx+ax) <= abs(xin*vmax) {
    vx += ax;
} else if abs(vy + ay) < abs(vy) {
    vy += ay;
} else if abs(vx + ax) < abs(vx) {
    vx += ax;
}

//collisions and movement

if place_meeting(x-vx,y-vy,oWall) {
    while !place_meeting(x-sign(vx),y-sign(vy),oWall) {
        y-=sign(vy);
        x-=sign(vx);
    }
    if !place_meeting(x,y-vy,oWall) {
        y -= vy;
    }
    if !place_meeting(x-vx,y,oWall) {
        x -= vx;
    }
} else {
    x -= vx;
    y -= vy;
}
Feel free to roast my code as well, like I said it's a bit scatterbrained and could be smaller and more organized.
 
Top