The AI of my enemies that I made for my game is simple. They just follow the player (more precisely, they look in the direction of the player and go forward)
Step Event:
if (instance_exists(obj_player)){
direction = point_direction(x,y,obj_player.x,obj_player.y);
}
speed = spd;
But they keep on overlapping each other and go on top of the player. I've tried researching but all the forums said was to use place_free() and xprevious & yprevious, but I have no idea how to use them. How do I fix this?
Thanks :)
You can read about this on the gamemaker documentation : https://docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/place_free.html
basically, what you want to do is avoid moving your instance if that means causing a collision. x_previous and y_previous will be used to cancel the move by going back to the previous position.
But I think it's better to check the place before moving, so I would add at the end of you script :
that way, the ennemy will stop instead of stepping above an other instance.
A little upgrade would be the following : if there is a collision detected, check if you can move along a single axis instead (x or y) and do it.