Beispiel #1
0
    void Move()
    {
        if (WayPointManager.instance.tile.ContainsKey(currentTile.Pos + direction))
        {
            if (direction != Vector2.zero)             //fix if pdist < tdist
            {
                isMoving = true;

                WP nextTile = GetTileFromPos(currentTile.Pos + direction);

                RotateUnit(direction);

                if (GetDistanceDirection(nextTile.Pos) < 0.01f)                  //Debug direction should only be changed at this point
                {
                    currentTile = nextTile;

                    if (currentTile.GetComponent <EnemyWP> () != null)                    //has EWP
                    {
                        currentWp = currentTile.GetComponent <EnemyWP>();


                        //Begin to look for new direction
                        if (WayPointManager.instance.tile.ContainsKey(currentTile.Pos + newDirection))
                        {
                            Checkdirections(currentWp, getTargetPos());
                        }
                    }
                }

                float newX = direction.x * uStats.BaseSpeed;
                float newZ = direction.y * uStats.BaseSpeed;

                transform.position += new Vector3(newX, 0, newZ) * Time.deltaTime;
            }
        }
        else
        {
            isMoving = false;
            Checkdirections(currentWp, getTargetPos());
        }
    }
 // if the destination is reached, everything will be cleared, so it can be repeated for the next destination
 public static void clearRoute()
 {
     destinationFound = false;
     routeFound       = false;
     foreach (GameObject WP in waypoints)
     {
         if (showCalculations)
         {
             WP.GetComponent <Waypoint>().distanceText.text  = "";
             WP.GetComponent <Waypoint>().distanceText.color = Color.black;
         }
         WP.GetComponent <Waypoint>().shortestDistance = 1000;
     }
     RoutePoints.Clear();
 }
Beispiel #3
0
    void Move()
    {
        //only change direction if input matches grid possibility's
        if (WayPointManager.instance.tile.ContainsKey(currentTile.Pos + direction))
        {
            isMoving = true;
            if (direction != Vector2.zero)
            {
                WP nextTile = GetTileFromPos(currentTile.Pos + direction);

                RotatePlayer(direction);

                // direction should only be changed at this point
                if (GetDistance(nextTile.Pos) < 0.01f)
                {
                    currentTile = nextTile;

                    if (currentTile.GetComponent <EnemyWP> () != null)
                    {
                        //		currentWp = GetWpFromPos (currentTile.Pos);

                        if (WayPointManager.instance.tile.ContainsKey(currentTile.Pos + newDirection))
                        {
                            ChangeDirection();
                        }
                    }
                }

                //enable going in reverse direction
                if (newDirection == direction * -1)
                {
                    //	currentWp = null;
                    ChangeDirection();
                }

                float newX = direction.x * pStats.playaSpeed;
                float newZ = direction.y * pStats.playaSpeed;

                transform.position += new Vector3(newX, 0, newZ) * Time.deltaTime;
            }
        }
        else
        {
            isMoving = false;
            ChangeDirection();
        }
    }