Пример #1
0
        private void OnTriggerStay(Collider other)
        {
            // If you don't plan on using degredation over distance, you can
            // remove OnTriggerStay entirely and lighten the load.
            dragger = GetComponent <FrameDragger>();
            FrameDragReceiver receiver = other.GetComponent <FrameDragReceiver>();

            if (receiver != null && receiver.isActiveAndEnabled)
            {
                if (degradeByDistance)
                {
                    // A full dragMagnitude (1.0) means the receiver almost
                    // perfectly matches the dragger's rotation and velocity.
                    // The magnitude should be full if the receiver is within
                    // the dragEffectRadius of the dragEffectOrigin.position,
                    // and degrade the further the object is from that radius.
                    //
                    // There are many ways to do this, and all of them should
                    // be smarter than this.
                    float receiverDistance = Vector3.Distance(receiver.transform.position, dragEffectOrigin.position);
                    receiver.dragMagnitude = Mathf.Clamp01(dragEffectRadius / receiverDistance);
                }
                else
                {
                    receiver.dragMagnitude = 1.0f;
                }
            }
        }
Пример #2
0
        private void OnTriggerEnter(Collider other)
        {
            dragger = other.transform.GetComponent <FrameDragger>();

            if (dragger != null && dragger.isActiveAndEnabled)
            {
                draggerRb = dragger.GetComponent <Rigidbody>();
            }
            else
            {
                // For safety's sake, remove any drag settings if we detect
                // entering a dragger that doesn't exist or isn't enabled.
                RemoveDrag();
            }
        }
Пример #3
0
 public void RemoveDrag()
 {
     dragger   = null;
     draggerRb = null;
 }