M
mmmestari
Guest
Hi!
I'm working on a grid-based game, in which certain objects in the game (such as the player and the enemies) move at the same time from one square to another. This is very much like it is in games like Crypt of the NecroDancer.
I have problems with how I should code collisions.
I first tried something like this. In this code, I tell the player to move one square right, if there is not an object already there that causes a collision.
Where o_ColCheck is the parent for every object that has a value for vCollision, and CanMove is the variable which checks whether sufficient time has elapsed since the last executed movement.
However, there are apparent problems with this approach. For instance, if two objects are trying to move to the same square, I would like to tell them both to stay where they are, even though there is not anything in the square they are trying to move to at that moment. Also, if I have an enemy following e.g. the player, the enemy does not move to the square the player is in, even if the player is leaving the square at the same time.
If someone could give me some direction, or link me some examples of how something like this has been done in prior projects, I'd be most grateful.
I'm working on a grid-based game, in which certain objects in the game (such as the player and the enemies) move at the same time from one square to another. This is very much like it is in games like Crypt of the NecroDancer.
I have problems with how I should code collisions.
I first tried something like this. In this code, I tell the player to move one square right, if there is not an object already there that causes a collision.
GML:
if (key_right and CanMove = true)
{
rightspeed = 32;
var _instL = instance_place(x + 32, y, o_ColCheck);
if (instance_exists(_instR))
{
if (_instR.vCollision = true)
{rightspeed = 0};
}
}
However, there are apparent problems with this approach. For instance, if two objects are trying to move to the same square, I would like to tell them both to stay where they are, even though there is not anything in the square they are trying to move to at that moment. Also, if I have an enemy following e.g. the player, the enemy does not move to the square the player is in, even if the player is leaving the square at the same time.
If someone could give me some direction, or link me some examples of how something like this has been done in prior projects, I'd be most grateful.