Circle collision stuck in block.

FullCup

Member
Could someone help me about the circle collision, I'm creating a game like 'Among Us' (movement), and I think a circle mask would be cool. However, it is hard to make the collision system so as not to get stuck in the block. How I'd like to do:1604262277538.png
You're just moving to the right, but the collision kinda takes you up, just like a slope system works. And I need it right, left, up and down.
 

PamiKA

Member
Well, it all depends on how you control the movements of your player. Ideally, you want absolute control over your collision system in the game, which means it is considered best to not use Collision Event and stick with Step Event as your main event for handling collision.
Since your aim is similar to the game Among Us then the movement is probably based on a vector that points to which direction should the character be moving towards. In this case, you must get the vector for the horizontal speed and the vertical speed from the direction from the touch input, then check ahead of the collision using place_meeting() and see if the next possible movement step conflicts with any collision and if so, you will then slowly clip the character to the wall and stop the movement. Kind of similar to how Shaun Spalding's old tutorials work.
 

FullCup

Member
Well, it all depends on how you control the movements of your player. Ideally, you want absolute control over your collision system in the game, which means it is considered best to not use Collision Event and stick with Step Event as your main event for handling collision.
Since your aim is similar to the game Among Us then the movement is probably based on a vector that points to which direction should the character be moving towards. In this case, you must get the vector for the horizontal speed and the vertical speed from the direction from the touch input, then check ahead of the collision using place_meeting() and see if the next possible movement step conflicts with any collision and if so, you will then slowly clip the character to the wall and stop the movement. Kind of similar to how Shaun Spalding's old tutorials work.
Yeah, thanks for the answer.

I'm using a collision system created with 'hspd' and 'vspd', checking for a collision before the next move. The movement is only for: right, left, up and down (diagonal too), so the vector would be just 'x + hspd, y + vspd'. The collision works only horizontally and vertically.

Here is the collision code i'm using.

GML:
//Horizontal
if place_meeting(x +hspd,y,obj_block)
{
      while !place_meeting(x +sign(hspd),y,obj_block) {x += sign(hspd);}
}
if place_meeting(x +sign(hspd),y,obj_block) {hspd = 0};

//Vertical/Diagonal
if place_meeting(x +hspd,y +vspd,obj_block)
{
      while !place_meeting(x +hspd,y +sign(vspd),obj_block) {y += sign(vspd);}
}
if place_meeting(x +hspd,y +sign(vspd),obj_block)  {vspd = 0};
 

muki

Member
I have a hack for this in my game. I dynamically shrink the collision circle when hsp is close to zero (when the instance gets stuck). It grows when the instance starts moving again. Clamped. All step event.

GML:
_vel = abs(x - x_prev);

if (_vel < 0.01) {
    _col -= 1;
} else {
    _col += 1;
}

_col = clamp(_col, 6, 12);
The radius is _col in my collision code:

GML:
collision_circle(x, y, _col, par_solid, false, true)
It helped in my case.
 
Top