GMS 2 Moving same objects not begin overlapping on mp_grid

I have tried each and every corner thing and solutions. But i have failed to avoid overlapping between two moving character. I also used the mp_potential_step which does not work in moving objects. It only works on static objects.

1. Using mp_grid for path finding.

2. Two moving character instances are of same object.

Possible cases (Approximate):i) A is moving in the grid and reach to B. Here, B is not moving doing a stuff work now.ii) B is moving in the grid and reach to A. Here, A is not moving doing a stuff work now.iii) A is moving in the grid and B is also moving. They can be collide on moving time.

How can i avoid them overlapping for all cases on mp_grid? Can anyone help me out?

I will glad to you. I am beginner at GM. Stuck in this bug some days!


I didn't work with mp_grids, but overlapping objects are a common problem. Shaun Spalding describes a prediction method in one of his platformer tutorials. The collision part begins at 19:35:

Hope this will help you out.


Well, ok... meanwhile i read something about mp_grids (here) and learned, that they are kind low resolution grids in wich instances can occupy single fields (and do AI stuff, of course). The reason for mp_potential_step to fail seems to be, that both instances begin movement before one of them occupied the target field. This seems to be indeed a different problem than the collision checking in Shaun's tutorial. 🤔

As I stated before, I didn't work with mp_grids. So what follows is speculative and will perhaps not work. I'm pretty sure, there are better solutions:
In "normal" grid based games you would change the content of the target field instantly. So the first instance called by the program would move and occupy the field and the next one called in the same frame would not begin to move, because the field is occupied. The idea is to fake this effect: you could move your instance and then build a temporary invisible wall that stops everything else that wants to move within the current grid field. This wall will be destroyed immediately in the End Step event. So the second instance should not enter the occupied field because of the invisible wall, but when the next frame starts, there will be no more invisible walls and the first instance can move freely.

Step events of your moving instances:
1) make a step in the desired direction (mp_potential_step avoiding solid objects)
2) build the invisible (but solid) wall in the current grid field

End step events of your invisible walls: