//Pass in a new path to be used when moving public void AcquirePath(Stack <GridSpace> _path) { Debug.Log("PATH ACQUIRED"); next_Space = _path.Pop(); next_Space.AddCombatCharacter(this); path = _path; future_Distance = (int)Vector2.Distance(grid_Position, target.grid_Position + target.future_Position); FaceDirection(new Vector2(next_Space.transform.position.x, next_Space.transform.position.z)); }
//Move the character according to their path public bool Moving(int current_Distance) { //Debug.Log(next_Space); //If the character does not have a path if (path == null) { return(false); } if (Vector3.Distance(transform.position, next_Space.transform.position) <= 0.1) { transform.position = next_Space.transform.position; future_Distance = (int)Vector2.Distance(grid_Position, target.grid_Position + target.future_Position); //If there are no more tiles to follow, or if the distance //between the target and this character grows, //Change path if (current_Distance <= range) { FaceDirection(new Vector2(target.transform.position.x, target.transform.position.z)); ResetPath(); return(false); } if (path.Count == 0 || current_Distance >= future_Distance) { ResetPath(); return(false); } //Get a new space to find next_Space.combat_Unit = null; next_Space = path.Pop(); //Change path if the next space is occupied if (next_Space.combat_Unit != null) { ResetPath(); return(false); } //Add the character to the path next_Space.AddCombatCharacter(this); future_Position = next_Space.grid_Position; FaceDirection(new Vector2(next_Space.transform.position.x, next_Space.transform.position.z)); } transform.position = Vector3.Lerp(transform.position, next_Space.transform.position, 0.1f); return(true); }