Beispiel #1
0
    /// <summary>
    /// Should be used as a check. YES"!?
    ///
    /// </summary>
    /// <returns>returns true if enemies are found.</returns>
    public void AggroCheck()
    {
        switch (base.myBehaviour)
        {
        case NPCBEHAVIOUR.FRIENDLY:
            break;

        case NPCBEHAVIOUR.HOSTILE:
            if (aggroTarget)
            {
                // AGGROCHECK
                if (Vector3.Distance(transform.position, aggroTarget.transform.position) < NPCAGGRODISTANCE)
                {
                    if (InternalTimer(FollowSightUpdateInterval))
                    {
                        if (SightCheck(aggroTarget.transform.position))
                        {
                            myState = NPCSTATE.COMBAT;
                        }
                    }
                }
            }
            break;
        }
    }
Beispiel #2
0
 // Use this for initialization
 void Start()
 {
     m_NPCSTATE                  = NPCSTATE.PATROL; //Setting State into Patrol
     m_NaveMeshAgent             = GetComponent <NavMeshAgent>();
     m_NaveMeshAgent.autoBraking = false;
     Zanimator = GetComponent <Animator>(); //Grabbing components
     HandleAnimation();
 }
Beispiel #3
0
 void CheckPlayer()
 {
     if (m_IsPlayerNear && CheckFieldOfView() && CheckOclusion())  //Checking to see if the view of the player is unobstructed
     {
         m_NPCSTATE = NPCSTATE.CHASE;
         HandleAnimation();
         return;
     }
     if (m_NPCSTATE == NPCSTATE.CHASE && !CheckOclusion())
     {
         m_NPCSTATE = NPCSTATE.PATROL;
         HandleAnimation();
     }
 }
Beispiel #4
0
    public override void Death()
    {
        myAnim  = NPCANIMATIONS.DEATH;
        myState = NPCSTATE.DEATH;
        if (collider)
        {
            DestroyImmediate(collider);
        }
        if (rigidbody)
        {
            DestroyImmediate(rigidbody);
        }

        if (animation["death"].time > animation["death"].length + NPCTIMEBEFOREDOWNED)
        {
            // Start falling through ground. 2 units?
            transform.position += (Vector3.down * Time.deltaTime) * NPCDEATHDOWNSPEED;
            Destroy(gameObject, 3.0f);
        }
    }
Beispiel #5
0
 /// <summary>
 /// 根据目标点判断NPC行为;
 /// </summary>
 /// <param name="vector">Vector.</param>
 void NpcUpdate(Vector3 vector)
 {
     if (Vector3.Distance(this.transform.position, vector) > atkDistance)
     {
         my_npcState = NPCSTATE.MOVE;
         m_Npc.Npc_Move(vector);
     }
     else
     {
         my_npcState = NPCSTATE.ATTCK;
         if (index == 0)
         {
             index = 1;
         }
         else
         {
             index = 0;
         }
     }
 }
Beispiel #6
0
 public void GoTo(Vector3 target)
 {
     gotoTarget = target;
     myState    = NPCSTATE.FOLLOW;
 }
Beispiel #7
0
    /// <summary>
    ///  Update every frame
    /// </summary>
    public override void Update()
    {
        if (!initialized)
        {
            initialized = Init();
        }

        if (Input.GetKeyDown(KeyCode.H))
        {
            AnimateOnce("gethitA");
        }

        if (Input.GetKeyDown(KeyCode.M))
        {
            friendlyTarget = GameObject.FindWithTag("Player");
            myState        = NPCSTATE.FOLLOW;
            myBehaviour    = NPCBEHAVIOUR.FRIENDLY;
        }

        if (Input.GetKeyDown(KeyCode.N))
        {
            Jump();
        }

        if (myState != NPCSTATE.DEATH)
        {
            grounded = GroundCheck();

            switch (myState)
            {
            case NPCSTATE.IDLE:
                AggroCheck();
                if (base.myBehaviour == NPCBEHAVIOUR.FRIENDLY && friendlyTarget != null)
                {
                    if (Vector3.Distance(transform.position, friendlyTarget.transform.position) > NPCSTARTFOLLOWDIST)
                    {
                        myState = NPCSTATE.FOLLOW;
                    }
                }

                if (usingPath)
                {
                    ResetPath();
                }
                break;

            case NPCSTATE.ROAM:
                AggroCheck();
                break;

            case NPCSTATE.COMBAT:
                if (base.myBehaviour == NPCBEHAVIOUR.FRIENDLY)
                {
                    // Help player in combat.
                }
                if (base.myBehaviour == NPCBEHAVIOUR.HOSTILE)
                {
                    // F**K DEM UP or IT or THAT or WHAT?
                    if (aggroTarget != null)
                    {
                        if (SightCheck(aggroTarget.transform.position))
                        {
                            if (!Move(aggroTarget.transform.position, HitDistance))
                            {
                                if (RotateTowards(aggroTarget.transform.position))
                                {
                                    AnimateOnce("punch");
                                    if (animation["punch"].time > animation["punch"].length * 0.2f)
                                    {
                                        if (attackCooldown <= 0)
                                        {
                                            attackCooldown = animation["punch"].length * 0.8f;
                                            MeleeDamage(this.gameObject, 1, 5.0f, ForceMode.Impulse);
                                        }
                                        else
                                        {
                                            attackCooldown -= Time.deltaTime;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;

            case NPCSTATE.ROUTINE:
                break;

            case NPCSTATE.FOLLOW:
                AggroCheck();
                if (gotoTarget != Vector3.zero)
                {
                    if (SightCheck(gotoTarget))     // Do we see target
                    {
                        Debug.Log("SEE IT!");
                        if (!Move(gotoTarget, 1.0f))
                        {
                            myState    = NPCSTATE.IDLE;  // CLose enough.
                            gotoTarget = Vector3.zero;
                        }

                        if (usingPath)
                        {
                            ResetPath();
                        }
                    }
                    else if (FollowingPath(gotoTarget))    // Get path and follow it.
                    {
                        myState = NPCSTATE.IDLE;
                    }
                }
                else if (base.myBehaviour == NPCBEHAVIOUR.FRIENDLY)
                {
                    // Follow player around.
                    if (friendlyTarget != null)
                    {
                        if (SightCheck(friendlyTarget.transform.position))     // Do we see target
                        {
                            if (!Move(friendlyTarget.transform.position, 1.0f))
                            {
                                myState = NPCSTATE.IDLE;     // CLose enough.
                            }
                            if (usingPath)
                            {
                                ResetPath();
                            }
                        }
                        else if (FollowingPath(friendlyTarget.transform.position))    // Get path and follow it.
                        {
                            myState = NPCSTATE.IDLE;
                        }
                    }
                }
                break;
            }
        }

        UpdateAnimations(); // State dependant animation update

        base.Update();
    }
Beispiel #8
0
 /// <summary>
 /// Should be used as a check. YES"!?
 /// 
 /// </summary>
 /// <returns>returns true if enemies are found.</returns>
 public void AggroCheck()
 {
     switch (base.myBehaviour)
     {
         case NPCBEHAVIOUR.FRIENDLY:
             break;
         case NPCBEHAVIOUR.HOSTILE:
             if (aggroTarget)
             {
                 // AGGROCHECK
                 if (Vector3.Distance(transform.position, aggroTarget.transform.position) < NPCAGGRODISTANCE)
                 {
                     if(InternalTimer(FollowSightUpdateInterval))
                     {
                         if (SightCheck(aggroTarget.transform.position))
                         {
                             myState = NPCSTATE.COMBAT;
                         }
                     }
                 }
             }
             break;
     }
 }
Beispiel #9
0
    public override void Death()
    {
        myAnim = NPCANIMATIONS.DEATH;
        myState = NPCSTATE.DEATH;
        if (collider) DestroyImmediate(collider);
        if (rigidbody) DestroyImmediate(rigidbody);

        if (animation["death"].time > animation["death"].length + NPCTIMEBEFOREDOWNED)
        {
            // Start falling through ground. 2 units?
            transform.position += (Vector3.down * Time.deltaTime) * NPCDEATHDOWNSPEED;
            Destroy(gameObject, 3.0f);
        }
    }
Beispiel #10
0
 public void GoTo(Vector3 target)
 {
     gotoTarget = target;
     myState = NPCSTATE.FOLLOW;
 }
Beispiel #11
0
    /// <summary>
    ///  Update every frame
    /// </summary>
    public override void Update()
    {
        if (!initialized) initialized = Init();

        if (Input.GetKeyDown(KeyCode.H))
        {
            AnimateOnce("gethitA");
        }

        if (Input.GetKeyDown(KeyCode.M))
        {
            friendlyTarget = GameObject.FindWithTag("Player");
            myState = NPCSTATE.FOLLOW;
            myBehaviour = NPCBEHAVIOUR.FRIENDLY;
        }

        if (Input.GetKeyDown(KeyCode.N))
            Jump();

        if (myState != NPCSTATE.DEATH)
        {
            grounded = GroundCheck();

            switch (myState)
            {
                case NPCSTATE.IDLE:
                    AggroCheck();
                    if (base.myBehaviour == NPCBEHAVIOUR.FRIENDLY && friendlyTarget != null)
                    {
                        if (Vector3.Distance(transform.position, friendlyTarget.transform.position) > NPCSTARTFOLLOWDIST)
                        {
                            myState = NPCSTATE.FOLLOW;
                        }
                    }

                    if (usingPath)
                        ResetPath();
                    break;
                case NPCSTATE.ROAM:
                    AggroCheck();
                    break;
                case NPCSTATE.COMBAT:
                    if (base.myBehaviour == NPCBEHAVIOUR.FRIENDLY)
                    {
                        // Help player in combat.
                    }
                    if (base.myBehaviour == NPCBEHAVIOUR.HOSTILE)
                    {
                        // F**K DEM UP or IT or THAT or WHAT?
                        if (aggroTarget != null)
                        {
                            if (SightCheck(aggroTarget.transform.position))
                            {
                                if (!Move(aggroTarget.transform.position, HitDistance))
                                {
                                    if(RotateTowards(aggroTarget.transform.position))
                                    {
                                        AnimateOnce("punch");
                                        if (animation["punch"].time > animation["punch"].length * 0.2f)
                                        {
                                            if (attackCooldown <= 0)
                                            {
                                                attackCooldown = animation["punch"].length * 0.8f;
                                                MeleeDamage(this.gameObject, 1, 5.0f, ForceMode.Impulse);
                                            }
                                            else
                                                attackCooldown -= Time.deltaTime;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                case NPCSTATE.ROUTINE:
                    break;
                case NPCSTATE.FOLLOW:
                    AggroCheck();
                    if (gotoTarget != Vector3.zero)
                    {
                        if (SightCheck(gotoTarget)) // Do we see target
                        {
                            Debug.Log("SEE IT!");
                            if (!Move(gotoTarget, 1.0f))
                            {
                                myState = NPCSTATE.IDLE; // CLose enough.
                                gotoTarget = Vector3.zero;
                            }

                            if (usingPath)
                                ResetPath();
                        }
                        else if (FollowingPath(gotoTarget))// Get path and follow it.
                        {
                            myState = NPCSTATE.IDLE;
                        }
                    }
                    else if (base.myBehaviour == NPCBEHAVIOUR.FRIENDLY)
                    {
                        // Follow player around.
                        if (friendlyTarget != null)
                        {
                            if (SightCheck(friendlyTarget.transform.position)) // Do we see target
                            {
                                if (!Move(friendlyTarget.transform.position, 1.0f))
                                    myState = NPCSTATE.IDLE; // CLose enough.

                                if (usingPath)
                                    ResetPath();
                            }
                            else if (FollowingPath(friendlyTarget.transform.position))// Get path and follow it.
                            {
                                myState = NPCSTATE.IDLE;
                            }
                        }
                    }
                    break;
            }
        }

        UpdateAnimations(); // State dependant animation update

        base.Update();
    }