Пример #1
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");
            }
        }
Пример #2
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;
         }
     }
 }
Пример #3
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();
        }
Пример #4
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));
        }
Пример #5
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);
            }
        }
Пример #6
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");
            }
        }