Esempio n. 1
0
    public override void Reason(Transform player, Transform npc)
    {
        //TO IMPLEMENT
        //Set the target position as the player position
        //Check the distance with player tank
        float distance = Vector3.Distance(player.position, npc.position);

        if (distance <= attackDistance)
        {
            controller.SetTransition(Transition.ReachPlayer);
        }

        float chaseRange = Vector3.Distance(player.position, npc.position);

        if (chaseRange > chaseDistance + 200f)
        {
            controller.SetTransition(Transition.LostPlayer);
        }

        if (controller.Health < (controller.maxHealth / 2))
        {
            controller.SetTransition(Transition.HalfHealth);
        }

        //When the distance is near, call the appropriate transition using SetTransition(Transition t) from NPCTankController
        //Also check when the player becomes too far, call the appropriate transition using SetTransition(Transition t) from NPCTankController
    }
Esempio n. 2
0
 public override void Reason(Transform player, Transform npc)
 {
     //TO IMPLEMENT
     //Check the distance with the player tank
     //When the distance is near, call the appropriate transition using SetTransition(Transition t) from NPCTankController
     if (CheckPlayerDistance(player, npc) >= 300f)
     {
         _npcController.SetTransition(Transition.SawPlayer);
     }
     //Also check when the player becomes too far, call the appropriate transition using SetTransition(Transition t) from NPCTankController
     if (CheckPlayerDistance(player, npc) >= 600f)
     {
         _npcController.SetTransition(Transition.LostPlayer);
     }
 }
Esempio n. 3
0
    public override void Reason(Transform player, Transform npc)
    {
        //TO IMPLEMENT
        //Check the distance with player tank
        float distance = Vector3.Distance(player.position, npc.position);

        if (distance <= chaseDistance)
        {
            controller.SetTransition(Transition.SawPlayer);
        }
        //When the distance is near, call the appropriate transition using SetTransition(Transition t) from NPCTankController

        if (controller.Health < (controller.maxHealth / 2))
        {
            controller.SetTransition(Transition.HalfHealth);
        }
    }
Esempio n. 4
0
    public override void Reason(Transform player, Transform npc)
    {
        //TO IMPLEMENT
        float distance = Vector3.Distance(player.position, npc.position);

        if (distance > attackDistance + 20f)
        {
            controller.SetTransition(Transition.SawPlayer);
        }
        if (controller.Health < (controller.maxHealth / 2))
        {
            controller.SetTransition(Transition.HalfHealth);
        }
        //Check the distance with the player tank

        //When the distance is near, call the appropriate transition using SetTransition(Transition t) from NPCTankController
        //Also check when the player becomes too far, call the appropriate transition using SetTransition(Transition t) from NPCTankController
    }
 public override void Reason(Transform player, Transform npc)
 {
     //TO IMPLEMENT
     //Check the distance with player tank
     //When the distance is near, call the appropriate transition using SetTransition(Transition t) from NPCTankController
     if (CheckPlayerDistance(player, npc) <= 500)
     {
         _npcTankController.SetTransition(Transition.SawPlayer);
     }
 }
Esempio n. 6
0
    public override void Reason(Transform player, Transform npc)
    {
        npcController = npc.GetComponent <NPCTankController>();

        //Set the target position as the player position
        destPos = player.position;

        //Check the distance with player tank
        //When the distance is near, transition to attack state
        float dist = Vector3.Distance(npc.position, destPos);

        if (npcController.GetCurrentHealth() >= (npcController.GetMaxHealth() / 1.5) && dist < 200f)
        {
            Debug.Log(npcController.GetCurrentHealth() + "Current health " + npcController.GetMaxHealth() + " Max health");
            Debug.Log("Switch to attack state");
            npcController.SetTransition(Transition.ReachPlayer);
        }
        else if (dist > 800f)
        {
            npcController.SetTransition(Transition.LostPlayer);
        }
    }
Esempio n. 7
0
    public override void Reason(Transform player, Transform npc)
    {
        NPCTankController npcScript = npc.GetComponent <NPCTankController>();

        npcScript.detectionTimer += Time.deltaTime;

        if (npcScript.detectionTimer >= npcScript.detectionRate)
        {
            if (npcScript.aggroType.ToString() == "LineOfSight")
            {
                //RaycastHit hit;
                //npcScript.rayDirection = player.position - npc.position;
                //if ((Vector3.Angle(npcScript.rayDirection, npc.forward)) < npcScript.FieldOfView)
                //{

                //    // Detect if player is within the field of view
                //    if (Physics.Raycast(npc.position, npcScript.rayDirection, out hit, npcScript.ViewDistance))
                //    {
                //        //get aspect on the hit
                //        Aspect aspect = hit.collider.GetComponent<Aspect>();
                //        if (aspect != null)
                //        {
                //            //Debug.Log("Hit something");

                //            if(aspect.aspectName == Aspect.aspect.Enemy)
                //            {
                //                Debug.Log("Enemy Seen");
                //                GameObject.FindWithTag("Player").GetComponent<PlayerScript>().isSeen = true;

                //                npcScript.SetTransition(Transition.SawPlayer);
                //            }
                //        }
                //        else
                //        {
                //            if (npcScript.CurrentStateID != FSMStateID.Patrolling)
                //                npcScript.SetTransition(Transition.LostPlayer);
                //        }
                //    }
                //}
            }
            else if (npcScript.aggroType.ToString() == "Sound")
            {
                //if palyer is in list and is moving, else invoke transidtion to patorl after
                if (npcScript.canHearObjects.Contains(player.gameObject))
                {
                    if (npcScript.canHearObjects.Count < 2)
                    {
                        //100% chance
                        npcScript.cantHearDebug = true;
                        GameObject.FindWithTag("Player").GetComponent <PlayerScript>().isHeard = true;
                        //npcScript.SetTransition(Transition.SawPlayer);
                    }
                    else
                    {
                        //Cuts chance in half depending on the amount of tanks in the list

                        int randNum;
                        randNum = Random.Range(1, 100);
                        Debug.Log("testRand");
                        if (randNum < (100 / (npcScript.canHearObjects.Count * 5)))
                        {
                            npcScript.cantHearDebug = true;
                            GameObject.FindWithTag("Player").GetComponent <PlayerScript>().isHeard = true;
                            //  npcScript.SetTransition(Transition.SawPlayer);
                        }
                    }
                }
            }
            else if (npcScript.aggroType.ToString() == "Touch")
            {
            }
            else if (npcScript.aggroType.ToString() == "Investigate")
            {
                if (npcScript.canHearObjects.Contains(player.gameObject))
                {
                    Debug.Log("Investigating");
                    npcScript.SetTransition(Transition.SmelledSardine);
                }
            }
            else
            {
            }
            npcScript.detectionTimer = 0;
        }

        if (Vector3.Distance(npc.position, player.position) <= 3.5f)
        {
            Debug.Log("Touched Player");
            player.GetComponent <PlayerScript>().FoundPlayer();
            npcScript.GetComponent <FieldOfView>().CatFoundPlayer(player);
            npcScript.agent.velocity = Vector3.zero;
            npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            npcScript.agent.isStopped = true;
        }
        if (Vector3.Distance(npc.position, waypoints[waypointCounter].position) <= 2.0f)
        {
            npcScript.agent.velocity = Vector3.zero;
            npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            npcScript.agent.isStopped = true;
            npcScript.pathingBuffer  += Time.deltaTime;

            if (npcScript.pathingBuffer > 1f)
            {
                npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
                npcScript.agent.isStopped = false;

                if (npcScript.pathing == PathingMode.Random)
                {
                    Debug.Log("findnextrand");
                    FindNextRandPoint();
                    npcScript.agent.SetDestination(destPos);
                }
                else if (npcScript.pathing == PathingMode.Order)
                {
                    if (waypointCounter < waypoints.Length - 1)
                    {
                        waypointCounter += 1;
                        npcScript.agent.SetDestination(waypoints[waypointCounter].position);
                    }
                    else
                    {
                        waypointCounter = 0;
                        npcScript.agent.SetDestination(waypoints[waypointCounter].position);
                    }
                }
                npcScript.pathingBuffer = 0;
            }
        }
    }
    public override void Reason(Transform player, Transform npc)
    {
        NPCTankController npcScript = npc.gameObject.GetComponent <NPCTankController>();

        if (npcScript.targetSardine == null)
        {
            npcScript.agent.isStopped = false;
            investigateTime           = 0;

            npcScript.findPointCounter = 0;
            Debug.Log("Waypoint count is" + waypointCounter);
            Debug.Log("Waypoing Length is" + waypoints.Length);
            //if (waypointCounter < waypoints.Length - 1)
            //{
            //    Debug.Log("+1");
            //    waypointCounter++;
            //    npcScript.agent.SetDestination(waypoints[waypointCounter].position);
            //}
            //else
            //{
            //    Debug.Log("0");
            //    waypointCounter = 0;
            //    npcScript.agent.SetDestination(waypoints[waypointCounter].position);

            //}
            npcScript.isEatingSardines = false;
            npcScript.SetTransition(Transition.LostPlayer);
        }
        else
        {
            distToSardine = Vector3.Distance(npc.position, npcScript.targetSardine.transform.position);

            investigateTime += Time.deltaTime;

            if (distToSardine <= 3.5f)
            {
                npcScript.agent.velocity = Vector3.zero;
                npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                npcScript.agent.isStopped = true;
            }
            if (investigateTime >= 6f)
            {
                investigateTime            = 0;
                npcScript.findPointCounter = 0;

                //if (waypointCounter < waypoints.Length - 1)
                //{
                //    waypointCounter += 1;
                //    npcScript.agent.SetDestination(waypoints[waypointCounter].position);
                //}
                //else
                //{
                //    waypointCounter = 0;
                //    npcScript.agent.SetDestination(waypoints[waypointCounter].position);

                //}
                npcScript.agent.isStopped = false;
                npcScript.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
                npcScript.isEatingSardines = false;
                npcScript.SetTransition(Transition.LostPlayer);
            }
        }
    }