Ejemplo n.º 1
0
 /// <summary> Create a Physics Joint between a grabable and a snapZone. </summary>
 /// <param name="grabable"></param>
 /// <param name="snapZoneBody"></param>
 /// <param name="breakForce"></param>
 public void CreateJoint(SG_Grabable grabable, Rigidbody snapZoneBody, float breakForce)
 {
     if (this.myJoint == null)
     {
         if (grabable.physicsBody != null)
         {
             this.myJoint = grabable.physicsBody.gameObject.AddComponent <FixedJoint>();
             this.myJoint.connectedBody   = snapZoneBody;
             this.myJoint.enableCollision = false;
             this.myJoint.breakForce      = breakForce;
         }
     }
     else
     {
         SG_Debugger.LogError("Multiple Physics connections to my Properties. Wrong index!");
     }
 }
Ejemplo n.º 2
0
 /// <summary> Check if all RigidBody settings allow us to pick up objects. </summary>
 protected void ValidateRB()
 {
     this.physicsBody = this.GetComponent <Rigidbody>();
     if (this.physicsBody != null)
     {
         if (this.physicsBody.useGravity)
         {
             SG_Debugger.LogWarning(this.name + ".DropZone has a rigidbody that uses gravity, and might move from its desired location.");
         }
     }
     else //we don't have a RigidBody, so one of the ObjectsToGet should have it!
     {
         if (this.objectsToGet.Count > 0)
         {
             bool noRBs = true;
             for (int i = 0; i < this.objectsToGet.Count; i++)
             {
                 if (this.objectsToGet[i].physicsBody == null)
                 {
                     SG_Debugger.LogWarning(this.objectsToGet[i].name + " will not be detected by " + this.name
                                            + ".DropZone, as neither have a RigidBody attached.");
                 }
                 else
                 {
                     noRBs = false;
                 }
             }
             if (noRBs)
             {
                 Debug.LogWarning("Since none of the ObjectsToGet in " + this.name + " have a RigidBody attached, one was autmatically attached to the GameObject.");
                 this.physicsBody             = this.gameObject.AddComponent <Rigidbody>();
                 this.physicsBody.useGravity  = false;
                 this.physicsBody.isKinematic = true;
             }
         }
         else
         {
             SG_Debugger.LogWarning(this.name + ".DropZone has no RigidBody of its own, and will therefore only " +
                                    "detect Grabables with a RigidBody attached.");
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary> Begin the interaction between this object and a GrabScript. </summary>
 /// <param name="grabScript"></param>
 /// <param name="fromExternal"></param>
 public bool BeginInteraction(SG_GrabScript grabScript, bool fromExternal = false)
 {
     if (grabScript != null)
     {
         if (this.isInteractable || fromExternal) //interactions only possible through these parameters.
         {
             bool begun = this.InteractionBegin(grabScript, fromExternal);
             if (begun)
             {
                 this.originalDist = (grabScript.grabReference.transform.position - this.transform.position).magnitude;
                 this.OnInteractBegin(grabScript, fromExternal);
                 return(true);
             }
         }
     }
     else
     {
         SG_Debugger.LogError("ERROR: You are attempting to start an interaction with " + this.name + " with grabscript set to NULL");
     }
     return(false);
 }
Ejemplo n.º 4
0
        /// <summary> Snaps an object to this Zone's snapPoint, based on the Grabable's grabType. </summary>
        /// <param name="grabable"></param>
        protected void AttachObject(SG_Grabable grabable)
        {
            grabable.SnapMeTo(this.snapPoint, true);
            grabable.InteractionBegun += Grabable_InteractionBegun;
            grabable.ObjectReset      += Grabable_ObjectReset;

            int index = ListIndex(grabable, this.objectsInside);

            if (this.snapMethod == SnapMethod.FixedJoint ||
                (this.snapMethod == SnapMethod.ObjectDependent && grabable.pickupMethod == GrabType.FixedJoint))
            {
                if (grabable.physicsBody != null)
                {
                    grabable.physicsBody.useGravity = true;
                    if (index > -1)
                    {
                        this.snapProperties[index].CreateJoint(grabable, this.physicsBody, SG_Grabable.defaultBreakForce);
                        this.snapProperties[index].isSnapped = true;
                    }
                }
                else
                {
                    SG_Debugger.LogWarning(grabable.name + " does not have a RigidBody to attach to " + this.name + " via PhysicsJoint.");
                }
            }
            else //any other way we snap it using the parent method.
            {
                grabable.pickupReference.parent = this.snapPoint;
                if (grabable.physicsBody != null)
                {
                    grabable.physicsBody.useGravity  = false;
                    grabable.physicsBody.isKinematic = true;
                }

                if (index > -1)
                {
                    this.snapProperties[index].isSnapped = true;
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary> Connect this Grabable's rigidBody to another using a FixedJoint </summary>
 /// <param name="other"></param>
 /// <returns>True, if the connection was sucesfully made.</returns>
 public bool ConnectJoint(Rigidbody other, float breakForce = SG_Grabable.defaultBreakForce)
 {
     if (other != null)
     {
         if (this.physicsBody)
         {
             this.connection = this.physicsBody.gameObject.AddComponent <FixedJoint>();
             this.connection.connectedBody   = other;
             this.connection.enableCollision = false;
             this.connection.breakForce      = breakForce;
             return(true);
         }
         else
         {
             SG_Debugger.Log("Using a FixedJoint connection requires a Rigidbody.");
         }
     }
     else
     {
         SG_Debugger.Log("No rigidbody to connect to " + other.name);
     }
     return(false);
 }