Beispiel #1
0
 /// <summary> Send an impact vibration to this script's connected glove, based on a speed in m/s. Checks for SG_RigidBodies. </summary>
 /// <param name="impactVelocity"></param>
 public void SendImpactFeedback(float impactVelocity, Collider col)
 {
     if (handLocation != SG_HandSection.Unknown && impactVelocity >= minImpactSpeed)
     {
         SG_TrackedBody rbScript;
         if (col == null || (col != null && !SG_TrackedBody.GetTrackedBodyScript(col, out rbScript))) //we either don't have a collider, or we do, but it doesn't have a RigidBody script.
         {
             int impactLevel;
             //evaluate the intensity
             if (impactVelocity > maxImpactSpeed || minImpactSpeed >= maxImpactSpeed)
             {
                 impactLevel = maxBuzzLevel;
             }
             else
             {
                 //map the impact parameters on the speed.
                 float mapped = Mathf.Clamp01(SG_Util.Map(impactVelocity, minImpactSpeed, maxImpactSpeed, 0, 1));
                 //we're actually start at minBuzzLevel; that's when you can start to feel the Sense Glove vibrations
                 impactLevel = (int)(SG_Util.Map(impactProfile.Evaluate(mapped), 0, 1, minBuzzLevel, maxBuzzLevel));
             }
             //actually send the effect
             if (linkedGlove != null && vibrationTime > 0)
             {
                 if (handLocation == SG_HandSection.Wrist) //it's a wrist.
                 {
                     linkedGlove.SendCmd(new SGCore.Haptics.TimedThumpCmd(impactLevel, vibrationTime));
                 }
                 else //finger
                 {
                     SGCore.Finger finger = (SGCore.Finger)handLocation; //can do this since the finger indices match
                     SGCore.Haptics.SG_TimedBuzzCmd buzzCmd = new SGCore.Haptics.SG_TimedBuzzCmd(finger, impactLevel, vibrationTime);
                     linkedGlove.SendCmd(buzzCmd);
                 }
                 cooldownTimer = 0; //reset cooldown for this finger.
             }
         }
     }
 }
Beispiel #2
0
        /// <summary> Access the ThrackedBody script off a collider </summary>
        /// <param name="col"></param>
        /// <param name="script"></param>
        /// <param name="favourSpecific"></param>
        /// <returns></returns>
        public static bool GetTrackedBodyScript(Collider col, out SG_TrackedBody script, bool favourSpecific = true)
        {
            SG_TrackedBody myScript = col.gameObject.GetComponent <SG_TrackedBody>();

            if (myScript != null && favourSpecific) //we favour the 'specific' material over a global material.
            {
                script = myScript;
                return(true);
            }
            //myMat might exist, but we favour the connected one if possible.
            SG_TrackedBody connectedMat = col.attachedRigidbody != null?
                                          col.attachedRigidbody.gameObject.GetComponent <SG_TrackedBody>() : null;

            if (connectedMat == null)
            {
                script = myScript;
            }                                                //the connected body does not have a material, so regardless we'll try the specific one.
            else
            {
                script = connectedMat;
            }
            return(script != null);
        }