#### ChrisSor54

##### Member

///@function collision_bounce()

///@description Checks for collision with objCollision and "bounces" player to nearest available space

function collision_bounce()

{

if place_meeting(x,y,objCollision)

{

for(var i = 0; !place_empty(x,y); i += 1; )

{

newY = y;

newX = x;

newY -= i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newY = y;}

newY += i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newY = y;}

newX -= i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newX = x;}

newX += i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newX = x;}

newY -= i; newY -= i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newY = y; newX = x;}

newY += i; newX += i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newY = y; newX = x;}

newY -= i; newX += i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newY = y; newX = x;}

newY += i; newX -= i; if place_empty(newX,newY) {x = newX; y = newY; continue;} else {newY = y; newX = x;}

}

}

}

While this system works, there are 2 main flaws. The first is that it can only check cardinal directions, i.e. North, South, NorthWest, SouthEast, etc, which would normally work fine enough (I don't really expect the player to be clipping through collisions much anyway which is where this would matter), but a bug I've noticed is that since it prioritizes certain directions by checking them before others, I run into situations where if the player runs into a corner they just clip through the wall. I know this is tied to which one is checked first, because by switching the order around the corner where this happens changes, but I don't understand the clipping issue.

My goal is to maybe try and fix this by instead using a different system. My idea would be to, when a collision was detected, draw a small circle around the player and check that circle for any open areas. If none were detected, the circles radius would increase by 1, and it would check again, until it found an available area. I'm still somewhat a noob at this as I've only been working with GML for like 2 weeks and it's my first programming language. Any help on what functions I can use to build this system? Thank you.