var target_distance = 40;
var distance_to_object = 0;

target_distance = distance_to_object(objPlayerParent);

if ( target_distance >= follow_distance )
    mp_potential_step_object(objPlayerParent.x, objPlayerParent.y, 1, objEnemyParent);

With this code, the enemy ships are chasing the player, but are still colliding with each other, they also rather fly around the player than following his trail.

mp_potential_step(objPlayerParent.x, objPlayerParent.y, 1, true)

This did not lead to the desired effect either.

How can I make an enemy to step around all solid objects in my level and follow the player at the given distance?

More context: The whole game plays in space and at the moment there are not many objects, but each type of object has it's own parent ( objPlayerParent, objEnemyParent, objPowerUpParent etc) and they are supposed to avoid all objects marked as solid. I also apologize for the quite noobish question but I am really new to advanced AI programming.


1 Answer 1


There are two popular solutions to your current problems.

- Steering:

enter image description here

- Pathfinding:

enter image description here

They can be implemented independently or in conjunction. Likely the easiest of the two to implement is steering. Steering also has the benefit of providing additional behaviors that can handle groups more easily, to avoid enemies colliding with each other when they're moving towards the player. The behaviors combined are called flocking.

There are lots of questions on this site that relate to implementing both pathfinding and steering. Additionally, the article linked above for steering has some excellent resources for implementing these behaviors.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .