Question by
diahnovianti · Jul 22, 2019 at 12:56 AM ·
gamepathfindingenemy aialgorithmfollow path
Enemy can't move follow the path, A* algorithm for my game
Hello.. I am working about implementation A* algorithm for my game and I want enemy follow the path which has been found.. but, there seems to be problem with the code:
void MovementTarget(List<Node> path) //this for movement npc
{
if (path.Count - 1 != 0)
{
if (distance >= 10)
{
speed = 2;
enemy.position = Vector3.MoveTowards(enemy.transform.position, new Vector3(path[0].worldPosition.x, enemy.position.y, path[0].worldPosition.z)
, Time.deltaTime * speed); //movement
}
else if (distance < 10)
{
speed = 1;
enemy.position = Vector3.MoveTowards(enemy.transform.position, new Vector3(path[0].worldPosition.x, enemy.position.y, path[0].worldPosition.z)
, Time.deltaTime * speed); //movement
}
}
}
the enemy cannot follow the path, especially when there is an obstacle, so enemy stop move to target. i'm very grateful if you can help me :)
Comment