Exemple #1
0
        public IEnumerator StartMelee()
        {
            //Stop aiming our weapon at the enemy
            rotateGunScript.Deactivate();

            //Rotate to face the target
            directionToFace   = -(myAIBodyTransform.position - myBaseScript.targetTransform.position);
            useCustomRotation = true;
            directionToFace.y = 0;

            //Make sure we're rotating
            while (isPlaying && myAIBodyTransform && myBaseScript.targetTransform && Vector3.Angle(directionToFace, myAIBodyTransform.forward) > maxAngleDeviation)
            {
                directionToFace   = -(myAIBodyTransform.position - myBaseScript.targetTransform.position);
                directionToFace.y = 0;

                //Debug stuff
                Debug.DrawRay(myTransform.position, myTransform.forward * 100, Color.magenta);
                Debug.DrawRay(myTransform.position, directionToFace * 100, Color.blue);
                yield return(null);
            }

            //Play teh animation
            if (isPlaying && myAIBodyTransform)
            {
                animator.SetTrigger(meleeHash);
                yield return(new WaitForSeconds(meleeAnimationLength));
            }
            useCustomRotation = false;
            rotateGunScript.Activate();
            myBaseScript.StopMelee();
        }
Exemple #2
0
        IEnumerator AICycle()
        {
            //Will stop if the script is disabled at any point.
            while (this.enabled)
            {
                if (currentBehaviour != null)
                {
                    currentBehaviour.AICycle();
                }

                //Check to see if we should dodge.
                //Dodges are automatically triggered after spending time in their target's line of sight
                if (!isDodging)
                {
                    if (myTransform && targetTransform && canMelee && !isMeleeing && Vector3.SqrMagnitude(myTransform.position - targetTransform.position) < meleeRange)
                    {
                        animationScript.StopSprinting();
                        SetProperSpeed();
                        headLookScript.Activate();
                        StartCoroutine(AttackInMelee());
                    }
                    else
                    {
                        if (!isMeleeing && Vector3.SqrMagnitude(myTransform.position - currentBehaviour.targetVector) > distFromTargetToSprint && canSprint && engaging)
                        {
                            animationScript.StartSprinting();
                            SetSprintSpeed();
                            headLookScript.Deactivate();
                        }
                        MoveAI();
                    }
                }

                if (Vector3.SqrMagnitude(myTransform.position - currentBehaviour.targetVector) < distFromTargetToSprint && engaging)
                {
                    animationScript.StopSprinting();
                    SetProperSpeed();
                    headLookScript.Activate();
                }
                yield return(new WaitForSeconds(cycleTime));
            }
        }