예제 #1
0
        /// <summary>Calculates the Pitch direction to Appy to the Rotator Transform</summary>
        internal void CalculatePitchDirectionVector()
        {
            var UpDown   = Mathf.Clamp(UpDownSmooth, -1, 1);
            var Vertical = Mathf.Clamp(VerticalSmooth, -1, 1);

            Vector3 PitchDirection;

            if (MoveWithDirection)                         //If the Animal is using Directional Movement use the Raw Direction Vector
            {
                PitchDirection = TargetMoveDirection;
                PitchDirection.Normalize();

                PitchDirection += (UpVector * UpDown);
            }
            else                                                                                         //If not is using Directional Movement Calculate New Direction Vector
            {
                if (MovementAxis.z < 0)
                {
                    UpDown = 0;                                                                         //Remove UP DOWN MOVEMENT while going backwards
                }
                PitchDirection = (transform.forward * Vertical) + (transform.up * UpDown);              //Calculate the Direction to Move
            }

            if (PitchDirection.magnitude > 1)
            {
                PitchDirection.Normalize();                                                        //Remove extra Speed
            }
            this.PitchDirection = Vector3.Slerp(this.PitchDirection, PitchDirection, DeltaTime * CurrentSpeedModifier.lerpRotation * 4);

            // if (debugGizmos) Debug.DrawRay(transform.position, this.PitchDirection * 5, Color.yellow);
        }
예제 #2
0
        /// <summary>Calculates the Pitch direction to Appy to the Rotator Transform</summary>

        private void CalculatePitchDirectionVector()
        {
            var UpDown   = Mathf.Clamp(Smooth_UpDown, -1, 1);
            var Vertical = Mathf.Clamp(VerticalSmooth, -1, 1);

            if (MoveWithDirection)                         //If the Animal is using Directional Movement use the Raw Direction Vector
            {
                PitchDirection = TargetMoveDirection;
                PitchDirection.Normalize();

                PitchDirection += (UpVector * UpDown);
                if (PitchDirection.magnitude > 1)
                {
                    PitchDirection.Normalize();                                                        //Remove extra Speed
                }
            }
            else                                                                                         //If not is using Directional Movement Calculate New Direction Vector
            {
                if (MovementAxis.z < 0)
                {
                    UpDown = 0;                                                                         //Remove UP DOWN MOVEMENT while going backwards
                }
                PitchDirection = (transform.forward * Vertical) + (transform.up * UpDown);              //Calculate the Direction to Move
                if (PitchDirection.magnitude > 1)
                {
                    PitchDirection.Normalize();                                                        //Remove extra Speed
                }
            }

            // if (debug) Debug.DrawRay(transform.position, PitchDirection, Color.yellow);
        }
예제 #3
0
    //function that starts playing a clip by name
    public void PlayAudioClip(string name, float pitchVariancePercent = 0, PitchDirection pitchD = PitchDirection.Both)
    {
        Audio a = AudioClipByName(name);

        if (a == null)
        {
            return;
        }
        float pitchVariance = pitchVariancePercent != 0 ? (pitchVariancePercent / 100) : 0;

        StartCoroutine(PlayOneShot(a, pitchVariance, pitchD));
    }
예제 #4
0
    public IEnumerator PlayOneShot(Audio a, float pitchVariance, PitchDirection direction)
    {
        AudioSource temp = gameObject.AddComponent <AudioSource>();

        a.AttachAudio(temp);
        float maxPitchDifference = pitchVariance * temp.pitch;
        float variance           = UnityEngine.Random.Range(direction != PitchDirection.Down ? -maxPitchDifference : 0, direction != PitchDirection.Up ? +maxPitchDifference : 0);

        temp.pitch = Mathf.Clamp(temp.pitch + variance, .3f, 3f);
        temp.Play();
        yield return(new WaitForSeconds(a.clip.length));

        Destroy(temp);
    }