I am making a 2D Top-down game and I am having trouble getting the enemy AI working properly. The enemy is following me properly, but it is getting stuck on objects in the way. How can I get the enemy to detect once it collides with an obstacle and interrupt the MoveTowards to change direction to hopefully avoid the obstacle?
The code that I am using for the enemy is as follows:
void FixedUpdate() { transform.position = Vector3.MoveTowards(transform.position,target.position,speed*Time.fixedDeltaTime); }
How can I detect if the enemy is colliding with an object and interrupt the MoveTowards function? Or is there a better way to do this?
Thanks.