- Home /
 
               Question by 
               chaaaardkun · Jan 26, 2017 at 11:21 AM · 
                characterdirectionwaypointai problems  
              
 
              AI faces Weird Direction when following a waypoint
My problem is that whenever it tries to movetowards the currentwaypoint, it faces weird directions and does not follow the path completely. heres the script.
IEnumerator FollowPath() { Vector3 currentWaypoint = path[0];
     while (true) {
         //transform.LookAt (currentWaypoint);
         if (transform.position == currentWaypoint) {
             
             PathRequestManager.RequestPath(transform.position,target.position,OnPathFound);
             targetIndex=0;
             targetIndex ++;
             //Debug.Log(currentWaypoint);
             if (targetIndex >= path.Length) {
                 targetIndex =0;
                 path = new Vector3[0];
                 //yield break;
             }
             currentWaypoint = path[targetIndex];
         }
         transform.LookAt (currentWaypoint);
         transform.position = Vector3.MoveTowards(transform.position,currentWaypoint,speed * Time.deltaTime);
             
         yield return null;
     }
 }
any help? currently using a* pathfinding. Complete source code is found here: https://github.com/SebLague/Pathfinding
As you can see here, it follows and faces the currentwaypoint correctly at first. 
but when it reached the current waypoint, it randomly changes its direction or randomly faces direction and does not go through the next waypoint. 
 
                 
                astar.jpg 
                (121.8 kB) 
               
 
                
                 
                astar2.jpg 
                (262.6 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                