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
        // Use this for initialization
        void Awake()
        {
            //initialize various values.
            //Mainly taking inputs from the user and putting them into the formats we use later,
            //eg: squared values for faster distance comparison.
            myTransform = transform;


            timeUntilNextDodge         = timeBetweenLoSDodges * Random.value;
            dodgeClearHeightCheckPos   = Vector3.zero;
            dodgeClearHeightCheckPos.y = dodgingClearHeight;

            distFromTargetToSprint = distFromTargetToSprint * distFromTargetToSprint;
            meleeRange             = meleeRange * meleeRange;

            if (gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>() != null)
            {
                agent                 = gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>();
                origAcceleration      = agent.acceleration;
                agent.speed           = idleSpeed;
                origAgentStoppingDist = agent.stoppingDistance;
            }
            else
            {
                Debug.LogWarning("No navmesh agent on the same object as the BaseScript!  Please add one!");
                this.enabled = false;
                return;
            }

            if (idleSpeed > runSpeed)
            {
                idleSpeed = runSpeed;
            }
            if (headLookScript)
            {
                headLookScript.Deactivate();
            }
        }