Question by 
               xSillusx · May 18, 2020 at 05:48 PM · 
                c#movementpathfindingslow  
              
 
              C# Unity Move the player along a* found path
Hello, I made that the a* algorithm find correct paths, i return every pathTile it found to the movement script, the player teleports instantly to the last position (which is fine i guess?) but i want the player object to slowly move towards it along every tile. heres how i made the movement
The following piece of code is used inside the Update() of my MovementHandler for the World/Player
 if(Input.GetKeyDown(KeyCode.Mouse0))
         {
             if(lastMouseOver != null)
             {
                 foreach(var pathTile in currentPath)
                 {
                     Vector3 nextPosition = new Vector3(pathTile.tilePosition.x, 0.15f, pathTile.tilePosition.z);
                     while (GetComponent<GlobalVariableHolder>().PlayerReference.transform.position != nextPosition)
                     {
                         float step = GetComponent<GlobalVariableHolder>().playerSpeed * Time.deltaTime;
                         GetComponent<GlobalVariableHolder>().PlayerReference.transform.position = Vector3.Lerp(GetComponent<GlobalVariableHolder>().PlayerReference.transform.position, nextPosition, step);
                     }
                     GetComponent<GlobalVariableHolder>().PLAYER_POS = nextPosition;
                 }
 
                 gameObject.GetComponent<GameBoardGenerator>().GenerateNextTiles(new Vector3(lastMouseOver.transform.position.x, -1, lastMouseOver.transform.position.z));
                 UnselectTiles();
             }
         }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Movement following the A* algorithm 0 Answers
Enemy AI using pathfinding to avoid obstacles 1 Answer
Need Help With Highschool Unity Game Design Project 0 Answers
Hexagonal Grid Rangefinding 1 Answer