Exemple #1
0
    void follow()
    {
        //agent.ResetPath();
        if (Vector3.Distance(transform.position, home) < 2)
        {
            if (stuckBlocker <= 0)
            {
                if (IsStuck(newPosition, oldPosition, oldPosition2))
                {
                    posTimer = 0;
                    posTimer = 5;
                    if (TestDebug)
                    {
                        print("resetting path");
                    }
                    agent.ResetPath();
                    previous2   = previous;
                    previous    = currentNode;
                    currentNode = null;
                    State       = InuState.Flee;
                    return;
                }
            }
        }
        seen = false;
        seen = SeeObject(PlayerObject, LevelMask, home);
        if (seen)
        {
            State         = InuState.Chase;
            nextFootprint = null;
            return;
        }
        if (nextFootprint == null)
        {
            foundFootprint = SeeFootprint(allNodes, LevelMask, home);
            if (foundFootprint == null)
            {
                nextFootprint = foundFootprint;
                State         = InuState.Idle;
            }
            if (foundFootprint != null)
            {
                nextFootprint = foundFootprint;
                agent.SetDestination(foundFootprint.transform.position);
            }
        }
        else
        {
            if (Vector3.Distance(transform.position, nextFootprint.transform.position) < 2)
            {
                nextFootprint = nextFootprint.getNext();
            }

            agent.SetDestination(nextFootprint.transform.position);
        }
    }
Exemple #2
0
    //function to execute in follow state, contains transitions, and code to follow footprints towards player
    void follow()
    {
        //agent.ResetPath();
        if (FleeInu(LevelMask, home))
        {
            State = OniState.Flee;
            return;
        }

        if (Vector3.Distance(transform.position, home) < 2)
        {
            //if positions have not changed enough determine Oni to be stuck and change behavior pattern
            //reset timers to give chance to move before checking again
            if (stuckBlocker <= 0)
            {
                if (IsStuck(newPosition, oldPosition, oldPosition2))
                {
                    posTimer = 0;
                    posTimer = 5;
                    if (TestDebug)
                    {
                        print("resetting path in patrol");
                    }
                    agent.ResetPath();
                    previous2    = previous;
                    previous     = currentNode;
                    currentNode  = null;
                    State        = OniState.Flee;
                    stuckBlocker = 30;
                    return;
                }
            }
        }
        seen = false;
        seen = SeeObject(PlayerObject, LevelMask, home);
        if (seen)
        {
            State         = OniState.Chase;
            nextFootprint = null;
            return;
        }
        //if there is no next footprint try to find a new footprint to follow
        if (nextFootprint == null)
        {
            foundFootprint = SeeFootprint(allNodes, LevelMask, home);
            if (foundFootprint == null)
            {
                State = OniState.Idle;
                return;
            }
            if (foundFootprint != null)
            {
                nextFootprint = foundFootprint;
                agent.SetDestination(foundFootprint.transform.position);
            }
        }
        //else move towards next footprint
        else
        {
            if (Vector3.Distance(transform.position, nextFootprint.gameObject.transform.position) < 2)
            {
                //update next footprint to continue following the trail
                nextFootprint = nextFootprint.getNext();
                if (nextFootprint == null)
                {
                    //print("next dne");
                }
            }
            if (nextFootprint != null)
            {
                //print("nextfootprint " + nextFootprint.gameObject.transform.position);
                agent.SetDestination(nextFootprint.gameObject.transform.position);
            }
        }
    }