Пример #1
0
 private void BowFullyDrawnHaptic()
 {
     if (HapticEffectWhenDrawAndReleased)
     {
         if (currentPull > maxPullDistance * pulledHapticPullThreshold && !pulled)
         {
             pulled = true;
             var impulse = ImpulseGenerator.BeginEmanatingEffect(WhichSide, 2);
             impulse.WithEffect(hapticOnDrawback).WithDuration(.25f).WithAttenuation(.5f);
             pulledHandle = impulse.Play();
         }
         else if (currentPull > maxPullDistance * pulledHapticPullThreshold && pulled)
         {
             pulledHapticCounter += Time.deltaTime;
             if (pulledHapticCounter > .25f)
             {
                 pulledHapticCounter = 0;
                 pulledHandle.Replay();
             }
         }
         else if (currentPull < maxPullDistance * pulledHapticPullThreshold * .5f)
         {
             pulled = false;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Desert of Danger - when the player is hit.
        /// This is not the best way to implement the following. We're still learning the best way to make reusable haptics.
        /// </summary>
        /// <param name="pos">This is used in tandem with the FindNearest() function that finds the AreaFlag that represents the closest point to the 'HitImpulse'</param>
        /// <param name="effect">This takes a different effect which can vary from projectile to projectile.
        /// You could also make a version that takes a CodeSequence for projectiles with varying characteristics</param>
        public void HitImpulse(Vector3 pos, string effect = "buzz")
        {
            //We have a function called FindNearestPos, which finds the closest AreaFlag on the player's body
            AreaFlag loc = AreaFlag.None;            //FindNearest(pos);

            //Then if we found something
            if (loc != AreaFlag.None)
            {
                //Then we begin an emanating effect on the player from that point.
                //We want the ENTIRE emanation to last .25 seconds, so we pass in that parameter.
                //Finally, we play the emanation.

                ImpulseGenerator.BeginEmanatingEffect(loc).WithEffect(effect, .1f).WithDuration(.25f).Play();

                //We let the HapticHandle Play returns go out of scope because the effect is short lived and we don't care about stopping it early.
                //If you had something like Daxter (the Weasel character from Jak and Daxter) climbing around on the player's body, you'd want to hold onto both the Impulse and the HapticHandle, that way you can restart the impulse (or change parameters) as well as being able to stop the haptic impulse when Daxter stops moving.

                //You could modify this function to return a HapticHandle or the created Impulse.
            }
            else
            {
                //We shouldn't ever be getting 'hit' without being able to find a valid nearby position.
                //An error is thrown inside of the FindNearest function (also provided)
                Debug.LogWarning("Invalid Hit at " + pos + "\n");
            }
        }
Пример #3
0
        private void ClickedSuitInTraversalMode(SuitBodyCollider clicked, RaycastHit hit)
        {
            //None are currently selected
            if (ImpulseOrigin == null)
            {
                //Select first
                ImpulseOrigin = clicked;

                //Mark it as selected
                ColorSuit(clicked, OriginColor);
            }
            //First one is already selected
            else
            {
                //If we click back on the first node.
                if (ImpulseOrigin == clicked)
                {
                    //Unselect First
                    ColorSuit(clicked, unselectedColor);
                    ImpulseOrigin = null;

                    //If we had a destination
                    if (ImpulseDestination != null)
                    {
                        //Clear it.
                        ColorSuit(ImpulseDestination, unselectedColor);
                        ImpulseDestination = null;
                    }
                }
                else
                {
                    //If we had a destination (from last play)
                    if (ImpulseDestination != null)
                    {
                        //Clear it to avoid leaving unnecessary colored nodes
                        ColorSuit(ImpulseDestination, unselectedColor);
                        ImpulseDestination = null;
                    }

                    //Set our destination
                    ImpulseDestination = clicked;
                    ColorSuit(clicked, OriginColor);

                    //Leftover log to see that we're playing from the start to end.
                    //Debug.Log((int)TraversalOrigin.regionID + "\t " + (int)suit.regionID);

                    //Play Impulse from the origin to our brand new destination.
                    ImpulseGenerator.Impulse imp = ImpulseGenerator.BeginTraversingImpulse(ImpulseOrigin.regionID, clicked.regionID);

                    //Then play it
                    ConfigureAndPlayImpulse(imp);
                }
            }
        }
Пример #4
0
        private void Start()
        {
            Effect whichEffect          = Effect.Pulse;         //What's more electrical than pulses.
            float  totalImpulseDuration = .35f;                 //How long does the shock take to traverse to the heart.
            float  effectDuration       = 0.0f;                 //0.0 defaults to the natural duration of the pulse effect.
            float  effectStrength       = 1;                    //How strong is the pulse effect

            //Create the Impulse object (which can be told to play, which instantiates what it 'is')
            shockImpulse = ImpulseGenerator.BeginTraversingImpulse(AreaFlag.Forearm_Right, AreaFlag.Chest_Left);

            // This sets the duration to be .25 seconds
            shockImpulse.WithDuration(totalImpulseDuration);

            //This defines the base effect (which needs an effect name, a strength and a duration)
            shockImpulse.WithEffect(whichEffect, effectDuration, effectStrength);
        }
Пример #5
0
        private void ReleaseArrowHaptics()
        {
            if (HapticEffectWhenDrawAndReleased)
            {
                pulledHandle.Stop();

                if (pulled)
                {
                    pulled = false;
                    var impulse = ImpulseGenerator.BeginEmanatingEffect(WhichSide, 2);
                    impulse.WithEffect(hapticOnRelease).WithDuration(.25f).WithAttenuation(.8f);
                    impulse.Play();
                }
            }
            ResetPulledHaptic();
        }
Пример #6
0
        /// <summary>
        /// This is a simple handful of lines. This plays when Walter (the giant red scorpion of player murdering) lands on the ground.
        /// This sample DOES work.
        /// The intention is to give an effect that goes up the body.
        /// It has been slightly adapted to take different effect families (click, double-click, hum, etc)
        /// </summary>
        public static void GiantScorpionLanding(string effect = "buzz")
        {
            //TWo different Impulses are used here even though the same one could be re-assigned. Two variables are more readable at neglible CPU cost.
            ImpulseGenerator.Impulse leftUp = ImpulseGenerator.BeginTraversingImpulse(AreaFlag.Lower_Ab_Left, AreaFlag.Forearm_Left)
                                              .WithDuration(0.5f)
                                              .WithEffect(effect, 0.1f, 1.0f);
            ImpulseGenerator.Impulse rightUp = ImpulseGenerator.BeginTraversingImpulse(AreaFlag.Lower_Ab_Right, AreaFlag.Forearm_Right)
                                               .WithDuration(0.5f)
                                               .WithEffect(effect, 0.1f, 1.0f);


            //Don't forget to play the effects
            leftUp.Play();
            rightUp.Play();

            //We could HapticHandle[] if we wanted to stop these prematurely - however they're very short effects, so it's unlikely that will be needed.
            //HapticHandle's can be Stopped or restarted until they (Finish playing AND go out of scope), after that they're gone.
        }
Пример #7
0
        /// <summary>
        /// Shoots the player body somewhere with a simple buzz emanation impulse.
        /// </summary>
        /// <param name="ShotWhere">Self explanator. DO NOT PROVIDE MULTIPLE AREAS.</param>
        /// <returns>Don't forget to call .Play() on the returned Impulse to create an instance of the haptic effect it defines.</returns>
        public static ImpulseGenerator.Impulse DesertOfDangerShot(AreaFlag ShotWhere = AreaFlag.Chest_Right)
        {
            CodeSequence seq = new CodeSequence();

            //This will be slightly different then the default "buzz" effect Impulse. If you ask for an effect with a duration of 0, it'll play the natural duration.
            //Natural durations range from .05s (click, buzz, etc) to .25s (the multiple click families)
            //So by providing a duration of .1, this will be slightly different than the line:
            //		CodeEffect eff = new CodeEffect("buzz", 0.00f, 1.0f);

            CodeEffect eff = new CodeEffect("buzz", 0.10f, 1.0f);

            seq.AddEffect(0, eff);

            //The Desert of Danger demo set the entire impulse duration to .25s,
            //this means that it emanated out from where the playerwas hit.
            return(ImpulseGenerator.BeginEmanatingEffect(ShotWhere)
                   .WithEffect(seq)
                   .WithDuration(.25f));
        }
Пример #8
0
        /// <summary>
        /// This is the Impulse that was used for the Desert of Danger recoil effect.
        /// It is imperfect in the implementation because it doesn't allow for flexibility to pick the effect.
        /// It could also take a more flexible Duration component but the core here is to give you what we used.
        /// Use ImpulseGenerator.CreateImpulse() function instead of modifying this.
        /// This sample does work.
        /// </summary>
        /// <param name="StartLocation">Pick the location to begin. DO NOT PROVIDE MULTIPLE AREAS.</param>
        /// <param name="EndLocation">Pick the destination to reach. DO NOT PROVIDE MULTIPLE AREAS.</param>
        /// <returns>Don't forget to call .Play() on the returned Impulse to create an instance of the haptic effect it defines.</returns>
        public static ImpulseGenerator.Impulse DesertOfDangerRecoil(AreaFlag StartLocation = AreaFlag.Forearm_Left, AreaFlag EndLocation = AreaFlag.Upper_Arm_Left)
        {
            //A simple code sequence
            CodeSequence seq = new CodeSequence();

            //The elements we will add
            CodeEffect eff  = new CodeEffect("buzz", 0.00f, 1.0f);
            CodeEffect eff2 = new CodeEffect("buzz", 0.15f, 0.5f);

            //The time stamps of the different effects.
            seq.AddEffect(0, eff);
            seq.AddEffect(.1, eff2);

            //In Desert of Danger, we used a duration of .1 seconds. This means the recoil effect took .1 seconds to hit ALL pads it aimed to. If you hand in different pads, it'll likely want a longer duration.
            //Since we only used the forearm and the upper arm, .1s is more than sufficient.
            //We could've used a file for this, but this was right as we were conceptualizing and beginning the usage of the ImpulseGenerator.
            return(ImpulseGenerator.BeginTraversingImpulse(StartLocation, EndLocation)
                   .WithDuration(.10f)
                   .WithEffect(seq));
        }
Пример #9
0
        public override void OnSuitClicked(SuitBodyCollider clicked, RaycastHit hit)
        {
            //Start with which mode this SuitDemo is in

            // Emanation - Start at a point and affect in waves the neighbor pads.
            if (CurrentMode == ImpulseType.Emanating)
            {
                //Debug.Log((int)suit.regionID + "\n");
                ImpulseGenerator.Impulse imp = ImpulseGenerator.BeginEmanatingEffect(clicked.regionID, (int)Depth);
                if (imp != null)
                {
                    ColorSuit(ImpulseOrigin, unselectedColor);
                    //Select first
                    ImpulseOrigin = clicked;

                    ConfigureAndPlayImpulse(imp);
                }
            }
            // Traversing - Start at a point and move in stages to the destination through neighbor pads
            else if (CurrentMode == ImpulseType.Traversing)
            {
                ClickedSuitInTraversalMode(clicked, hit);
            }
        }
Пример #10
0
        /// <summary>
        /// [Note: this does not work]
        ///
        /// </summary>
        /// <param name="playerBody"></param>
        /// <param name="info"></param>
        public void DynamiteExplosionSample(GameObject playerBody, ExplosionInfo info)
        {
            //Again, we checked what was the closest place to the explosion for starting an impulse.
            AreaFlag loc = FindNearest(playerBody, info.explosionCenter);

            if (loc != AreaFlag.None)
            {
                //This is a little gross but the idea is simple: Closer to the explosion, the longer the effect.
                //If you're close to dynamite the visuals take longer to dissipate and you'll spend longer thinking 'Oh man I screwed up' even though you're unharmed.
                //This is accomplished in a couple of ways:

                //The emanation will traverse farther across the user's body.
                int depth = 8;

                //The emanation will restart several times
                int repeats = 3;

                //The starting strength of the effect will be stronger.
                float strength = 1.0f;

                //The delay between the repetitions will be shorter.
                float delay = .15f;

                //We do a simple bit of checking based on the distance from the blast.
                if (info.dist > 0)
                {
                    //We base the depth off of the distance from the explosion.
                    //There is some magic-numbering going on here. You can tune it or standardize your distances.

                    //The farther, the less depth of the emanation
                    depth = (int)(8 / info.dist);
                    //The farther, the less initial strength - NOTE: this is just Effect strength, not using the Attenuation which is still a bit incomplete.
                    strength = 2 / info.dist;
                }

                //The closer the player is to the explosion, the more the explosion will 'reverberate' by repeating.
                repeats = Mathf.RoundToInt(Mathf.Clamp(7 / info.dist, 0, 7));

                //If we're going to experience it a lot, we'll get a shorter delay between the repeats.
                if (repeats > 4)
                {
                    delay = .1f;
                }

                //Start at the correct spot.
                ImpulseGenerator.Impulse impulse = ImpulseGenerator.BeginEmanatingEffect(loc, depth)
                                                   //Give the total effect a short duration (which you could choose to modify)
                                                   .WithDuration(.15f)
                                                   //Start with a natural duration click for the initial hit. This is good because it gets the motors going earlier on
                                                   .WithEffect("click", .00f, strength)
                                                   //Finish with a buzz which will last longer than natural duration. This gives the explosion a residual impact feeling
                                                   .WithEffect("buzz", .15f, strength);

                //Finally, we call the coroutine that will repeatedly create new handles of the impulse with Play().
                //Remember, an Impulse is like a prefab or a building plan for haptics. You can 'instantiate' multiple haptic effects off the same Impulse.
                StartCoroutine(RepeatedEmanations(impulse, delay, repeats));
            }
            else
            {
                Debug.LogWarning("Invalid Hit at " + info.explosionCenter + "\n");
            }
        }
Пример #11
0
 /// <summary>
 ///   Creates a new Comb filter.
 /// </summary>
 ///
 public CombFilter(int bpm, int pulses, int length, int samplingRate)
 {
     this.impulseGenerator = new ImpulseGenerator(bpm, pulses, samplingRate, SampleFormat.Format128BitComplex);
     this.length           = length;
     generateBaseSignal();
 }