Beispiel #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!PFNC.GNNCFinished() && USEPF)
        {
            PFNC.GNNCProgress();
        }

        PFNC.currentNode = PFNC.GNNCReturn();           // NOTE: This may screw things up further down the line.

        if (Time.time - lastTargetCheck > targetCheckDelay)
        {
            checkTarget();

            if (!alerted)
            {
                checkAnyVisible();
            }
            else
            {
                if (USEPF && PFNC.GNNCFinished())
                {
                    PFNC.currentNode = PFNC.getNodeNearestCover();
                }
            }

            lastTargetCheck = Time.time;
        }

        // IF in position, we are ready.

        if (USEPF && PFNC.GNNCFinished())
        {
            ready = ((int)transform.position.z == (int)getZXPosition(PFNC.currentNode.transform.position).z&&
                     (int)transform.position.x == (int)getZXPosition(PFNC.currentNode.transform.position).x);
        }
        else
        {
            ready = true;
        }


        // DEBUG: print (transform.position.ToString() + " : " + getZXPosition(PFNC.currentNode.transform.position));

        if (alerted)
        {
            // If alerted, and time has passed, and we are near the target node
            if (USEPF && PFNC.GNNCFinished())
            {
                if (Time.time > lastUpdate + updateInterval && Vector3.Distance(transform.position, PFNC.currentNode.transform.position) < 1)
                {
                    lastUpdate = Time.time;

                    // Change this to whatever the best method is.
                    // TODO: change to getSafest, once that works.
                    //PFNC.currentNode = PFNC.getNodeNearest();											// This should be the same for all
                    // Enemies.
                    //if (USEPF) PFNC.currentNode = PFNC.getNodeClosestToEnemies(GameObject.FindGameObjectsWithTag("Combatant"), faction);

                    ready = false;
                }
            }
        }
        else
        {
            // If not alerted and on a patrol
            if (patrol.Length != 0)
            {
                if (ready)
                {
                    patrolIndex = (patrolIndex + 1) % patrol.Length;
                }
                PFNC.currentNode = patrol[patrolIndex];
                float heading = (CC.velocity.sqrMagnitude > 0 ? Quaternion.LookRotation(CC.velocity, Vector3.up).eulerAngles.y : 0);
                transform.eulerAngles.Set(transform.eulerAngles.x, heading, transform.eulerAngles.z);
            }
        }

        if (USEPF && PFNC.GNNCFinished())
        {
            Vector3 target = getRelativePosition(transform, PFNC.currentNode.transform.position);
            target.Normalize();
            CC.SimpleMove(transform.InverseTransformDirection(target) * speed);
        }

        childFixedUpdate();
    }