// Use this for initialization
    void Start()
    {
        orbitDirection = 1; // clockwise
        orbitRadius    = 2.0f;
        orbitTimer     = 0f;
        // wanderTimer = 10f;
        // wanderRadius = 10f;
        agent = gameObject.GetComponent <NavMeshAgent>();
        timer = wanderTimer;

        if (gameObject.tag == "EnemyMinion")
        {
            target     = GameObject.FindGameObjectWithTag("Player").gameObject;
            targetBase = GameObject.FindGameObjectWithTag("PlayerBase").gameObject;
        }
        else if (gameObject.tag == "PlayerMinion")
        {
            targetBase = GameObject.FindGameObjectWithTag("EnemyBase").gameObject;
        }
        ChangeState(STATE.GoToOpponentBase);
        dest = DESTINATION.None;

        path = new NavMeshPath();
        NavMeshHit navHit;
        Vector3    testTarget = new Vector3(targetBase.transform.position.x, transform.position.y, targetBase.transform.position.z);
        bool       pointFound = NavMesh.SamplePosition(testTarget, out navHit, 10.0f, NavMesh.AllAreas);
        // Debug.Log("pointFound: " + pointFound + " testTarget: " + testTarget +  " navHit: " + navHit.position);
        bool pathFound = NavMesh.CalculatePath(transform.position, navHit.position, NavMesh.AllAreas, path);
        // Debug.Log("pathFound: " + pathFound);
        // foreach (Vector3 corner in path.corners) Debug.Log(corner);
    }
    private void GoToOpponentBase()
    {
        // if (path == null) return;
        // float distanceToTravel = 1f;
        // for (int i = 0; i < path.corners.Length - 1; i++)
        // {
        //     Debug.Log("GoToOpponentBase");
        //     float distance = Vector3.Distance(path.corners[i], path.corners[i + 1]);
        //     if (distance < distanceToTravel)
        //     {
        //         distanceToTravel -= distance;
        //         continue;
        //     }
        //     else
        //     {
        //         Vector3 pos = Vector3.Lerp(path.corners[i], path.corners[i + 1], distanceToTravel / distance);
        //         transform.position = pos;
        //         break;
        //     }
        // }

        if (agent == null || targetBase == null)
        {
            return;
        }
        if (dest != DESTINATION.OpponentBase)
        {
            agent.SetDestination(targetBase.transform.position);
            dest = DESTINATION.OpponentBase;
            Debug.Log("Setting destination - opponent base");
        }
        agent.isStopped = false;
    }
Exemple #3
0
    void OnTriggerExit2D(Collider2D other)
    {
        if(other.tag.Contains("Conveyor"))
            mColliderCount--;

        if(mColliderCount <= 0 && other.tag != "DestroyedPackage")
        {
            gameObject.tag = "DestroyedPackage";

            mDirection = DIRECTIONS.NONE;
            mDestination = DESTINATION.NONE;

            updateSprite();
        }
    }
Exemple #4
0
 public void setDestination(DESTINATION destination)
 {
     mDestination = destination;
     updateSprite();
 }
 public void SetDestination(DESTINATION destination)
 {
     dest = destination;
 }