- Home /
Question by
alpayoguz97 · Nov 25, 2020 at 01:33 PM ·
gameobjectpathfollowingwaypoint system
AI doesn't follow the path
Hey Guys,
I'm trying to made enemy gameobject follow the path. But It didn't work and I couldn't find the solution
Here is my following codes :
public class EnemyPath : MonoBehaviour
{
[SerializeField] List<Transform> waypoints;
[SerializeField] float enemySpeed;
int waypointIndex = 0;
void Start()
{
transform.position = waypoints[waypointIndex].transform.position;
}
// Update is called once per frame
void Update()
{
EnemyMovePath();
}
private void EnemyMovePath()
{
if (waypointIndex <= waypoints.Count - 1)
{
var targetPosition = waypoints[waypointIndex].transform.position;
var movementIndependenceFrame = enemySpeed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementIndependenceFrame);
if (transform.position == targetPosition)
{
waypointIndex++;
}
}
else
{
Destroy(gameObject);
}
}
}
Comment
Best Answer
Answer by alpayoguz97 · Nov 26, 2020 at 07:12 AM
I found the solution. Waypoints z axis is different than AI gameobject z axis. That's why AI gameobject doesn't follow the path.
Your answer

Follow this Question
Related Questions
whether the player can react based on user input while following in the waypoint system? 0 Answers
physics based path system? 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Make player follow a waypoint path but still be able to control player movement 1 Answer
How can I save gameObject? 1 Answer