Exemplo n.º 1
0
 void searching()
 {
     if (TimerContainer.wait(8, 3f, 8f))
     {
         print("Player not found, searching for a wander position");
         chooseDest();
     }
     else if (behaviors.name != "Searching")
     {
         navMesh.Stop();
         movementHandler(targetSighted);
     }
 }
Exemplo n.º 2
0
    void Update()
    {
        if (increasedAggressionTesting)
        {
            aggressionLevel += TimerContainer.wait(4, 5f, -2, 10, 7); //wait for 5 to 10 seoconds, and increase the
        }
        else
        {
            aggressionLevel += TimerContainer.wait(4, 30, -2, 45, 7);
        }

        for (int i = 0; i <= behaviorObjects.Length - 1; i++)
        {
            if (behaviorObjects[i].activeInHierarchy)      //loops through and finds an active object for the current behavior
            {
                currentBehavior = behaviorObjects[i].name; //Assings the current behavrior to a string so we can use it later
                break;                                     //We've already found the current behavior, so exit the loop.
            }
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            aggressionLevel = 100;
        }

        targetSighted = EnemyController.targetSighted;
        if (targetSighted == false && currentBehavior != "Searching")
        {
            print("Searching behavior chosen.");
            setBehavior(0);
        }
        else if (targetSighted == true /*&& currentBehavior == "Searching"*/)
        {
            targetFound(EnemyController.targetSighted, targetSightedRecently);
        }
        else
        {
            /*print("There's been an error with deciding behaviors... no paramaters were met.");
             * print("Current time: " + Time.time);
             * print(EnemyController.targetSighted);
             * print(targetSighted);
             * print(currentBehavior);*/
        }
        targetSightedRecently = false;
    }
Exemplo n.º 3
0
 void targetFound(bool yesNo, bool recently) //Target sighted and recently
 {
     if (yesNo == true)
     {
         if (TimerContainer.wait(5, 10f, 30f))
         {
             print("Time to wait until next check: " + TimerContainer.timer[5]);
             chooseBehavior();
         }
         else if (recently == true)
         {
             print("Update required before timer struck.");
             chooseBehavior();
         }
     }
     else
     {
         print("There was an error... player was not really found?");
         print("Current time: " + Time.time);
         print(EnemyController.targetSighted);
         print(targetSighted);
         print(currentBehavior);
     }
 }
Exemplo n.º 4
0
    public void movementHandler(bool playerFound)
    {
        playerFound = EnemyController.targetSighted;
        if (playerFound == false)
        {
            //Makes sure we can run the check if the ghost is stuck
            if (TimerContainer.wait(6, 0.5f))
            {
                checks[lastCheck]  = rb.position;
                lastCheck         += 1;
                ghostReportedStuck = false;
                checkPositions();
                if (lastCheck >= 6) //Resets the points recorded to check if the ghost is stuck.
                {
                    lastCheck = 0;
                    resetChecks();
                }

                if (!ghostReportedStuck)
                {
                    print("There are no one positions that are the same.  Continue as normal!");
                }
                else
                {
                    print("The ghost has reported being stuck.  Searching for a new position!");
                    chooseDest();
                }
            }
            if (behaviors.name == "Searching")
            {
                if (TimerContainer.wait(7, 2f))
                {
                    print("Searching behavior chosen.");
                    searching();
                }
            }
            else
            {
                print("There was an erorr. Searching behavior is not active, but player is not found!");
            }
        }
        else
        {
            if (behaviors.name == "Aggressive")
            {
                if (TimerContainer.wait(7, 2f))
                {
                    print("Aggressive behavior chosen");
                }
                aggressive();
            }
            else if (behaviors.name == "Stalking")
            {
                if (TimerContainer.wait(7, 2f))
                {
                    print("Stalk behavior chosen");
                    stalk();
                }
            }
        }
    }
Exemplo n.º 5
0
    void runDetection(float distance, bool targetAlreadyFound = false)
    {
        //check if we can detect player
        bool tryToFind = true;

        if (distance >= 40 && distance < 150)
        {
            minChance = (-Mathf.RoundToInt(distance) + Mathf.RoundToInt(detectionDistPlayer)); //lowest min chance is -15.
            maxChance = 100 + (Mathf.RoundToInt(distance) - Mathf.RoundToInt(maxViewDist));    //lowest max chance is 120.
        }
        else if (distance >= 150)                                                              //makes it a 0% chance for the ghost to find the player after 150 feet distance.
        {
            print("There is no chance to find the player... must wander....");
            tryToFind = false;
        }
        else if (!targetAlreadyFound)
        {
            if (distance < 40 && distance > 20)
            {
                minChance = 100; //makes it a 17.3% chance for the ghost to fail to find the player if they are less then 40 units away.
            }
            else if (distance <= 20)
            {
                minChance = 115; //makes it a 4.2% chance the ghost will fail to find the player if they are less then 20 feet away.
            }
        }
        else if (targetAlreadyFound)
        {
            //this needs to change how calculations are done so that the player has a chance to escape and the ghost goes back to searching like before.
            if (distance <= 20)
            {
                minChance = 119;
            }
            else if (distance >= 70 && distance < 150)
            {
                if (targetInfront)
                {
                    if (TimerContainer.wait(2, 10f)) //Timer to make sure the ghost is given time before decreasing the chance
                    {
                        minChance = 100;
                    }
                    else
                    {
                        minChance = 110;
                    }
                }
                else
                {
                    if (TimerContainer.wait(3, 10f)) //Second timer to make sure the ghost is given time before decreasing the chance
                    {
                        minChance = 90;
                    }
                    else
                    {
                        minChance = 100;
                    }
                }
            }
        }

        if (tryToFind)                                          //this tells us if we CAN check for the player.
        {
            detectionRoll = Random.Range(minChance, maxChance); //the ROLL

            if ((maxChance + minChance) > maxChance)            //this is meant to make sure the required min role does not exceed possible roles.
            {
                if (distance < 40 && distance > 20)
                {
                    int aditionalChances = (maxChance - minChance) / 4;
                    detectionChance = minChance + aditionalChances;
                }
                else if (distance <= 20)
                {
                    int aditionalChances = (maxChance - minChance) / 10;
                    detectionChance = minChance + aditionalChances;
                }
            }
            else
            {
                detectionChance = maxChance + minChance; //Min required roll to detect player
            }

            bool agroDetectIncrease = false;

            if (targetAlreadyFound == true)
            {
                print("Target is found.  Decreasing chance of losing target. (-40)");
                detectionChance -= 40;
                if (agroDetectIncrease == false)
                {
                    if (Behavior.aggressionLevel >= 100 || chosenBehavior.name == "Aggressive")
                    {
                        print("Ghost is aggressive.  Decreasing chance further. (-60)");
                        detectionChance   -= 60;
                        agroDetectIncrease = true;
                    }
                }
                agroDetectIncrease = false;
            }

            if (targetInfront) //Pretty straight forward... if target is infront... increase the odds of finding the player.
            {
                print("Target is in front of ghost.  Decreasing chance of losing target. (-30)");
                detectionChance -= 30;
                if (agroDetectIncrease == false)
                {
                    if (Behavior.aggressionLevel >= 100 || chosenBehavior.name == "Aggressive")
                    {
                        print("Ghost is aggressive.  Decreasing chance further. (-60)");
                        detectionChance   -= 60;
                        agroDetectIncrease = true;
                    }
                }
                agroDetectIncrease = false;
            }
            else
            {
                if (distance > 70)
                {
                    print("Ghost is not close to target.  Increasing chance of losing target. (+15)");
                    detectionChance += 15;
                }
            }

            print("Final result of the ghost detecting the player: " + detectionChance);

            if (detectionRoll >= detectionChance) //Should run when the ghost finds the player.
            {
                targetSighted = true;
                Behavior.recentlySighted();
            }
            else
            {
                if (targetSighted)
                {
                    targetSighted = false;
                    print("Target was lost.");
                    print(detectionChance);
                    print(detectionRoll);
                }
            }
        }

        else //this should run if the ghost fails to find the player
        {
            targetSighted = false;
        }
    }
Exemplo n.º 6
0
    void Update()
    {
        float distance = Vector3.Distance(target.position, transform.position);

        distanceFromPlayer = distance;
        time = Time.time;

        chosenBehavior = GameObject.FindGameObjectWithTag("Behaviors");

        if (Behavior.aggressionLevel >= 100)
        {
            scream.SetActive(true);
        }
        else if (Behavior.aggressionLevel <= 75)
        {
            scream.SetActive(false);
        }

        if (targetSighted && distance >= 150)
        {
            targetSighted = false;
        }

        detectionDistPlayer = PlayerControllerMovements.detectionDist; //pulls the info from the player movement script to see what the weight of detection is from them.

        //check if we are facing player
        float dot = Vector3.Dot(transform.forward, (target.position - transform.position).normalized);

        if (dot > 0.7f)
        {
            targetInfront = true;
        }
        else
        {
            targetInfront = false;
        }
        //facing player check end.

        if (TimerContainer.wait(1, 4f, 8f)) //handles the timer to check and see if the target can be found.
        {
            detectionRoll = 0;
            runDetection(distance, targetSighted);
            print("Detection check ran.  Next check at: " + TimerContainer.timer[1]);
        }
        else if (Input.GetKeyDown(KeyCode.I))
        {
            detectionRoll = 0;
            print("Forcing detection check");
            runDetection(distance, targetSighted);
        }

        if (Input.GetKeyDown(KeyCode.P)) //enter debugging mode
        {
            if (debugging)
            {
                debugging = false;
            }
            else
            {
                debugging = true;
            }
        }

        if (debugging)
        {
            Vector3 right = (transform.TransformDirection(Vector3.forward) + transform.TransformDirection(Vector3.right)) * 100;
            Vector3 left  = (transform.TransformDirection(Vector3.forward) - transform.TransformDirection(Vector3.right)) * 100;
            Debug.DrawRay(transform.position, right, Color.green);
            Debug.DrawRay(transform.position, left, Color.green);
            Debug.DrawRay(transform.position, transform.forward, Color.yellow);
            Debug.DrawRay(transform.position, (target.position - transform.position).normalized, Color.yellow);
        }
    }