protected override void StartGrab(BaseGrabber grabber) { base.StartGrab(grabber); transform.SetParent(grabber.GrabHandle); gameObject.GetComponent <Rigidbody>().isKinematic = true; transform.rotation = transform.parent.rotation; }
protected override void StartGrab(BaseGrabber grabber) { base.StartGrab(grabber); transform.SetParent(GrabberPrimary.transform); gameObject.GetComponent <Rigidbody>().isKinematic = true; }
public virtual bool TryGrabWith(BaseGrabber grabber) { // TODO error checking, multi-grab checking if (GrabState != GrabStateEnum.Inactive) { switch (grabStyle) { case GrabStyleEnum.Exclusive: // Try to transfer ownership of grabbed object BaseGrabber primary = GrabberPrimary; if (GrabberPrimary.CanTransferOwnershipTo(this, grabber)) { // Remove from grabbable list and detach activeGrabbers.Remove(primary); DetachFromGrabber(primary); } else { // If we can't, it's a no-go return(false); } break; case GrabStyleEnum.Multi: break; default: throw new ArgumentOutOfRangeException(); } } StartGrab(grabber); return(true); }
/// <summary> /// Specify the target and turn off gravity. Otherwise gravity will interfere with desired grab effect /// </summary> protected override void StartGrab(BaseGrabber grabber) { base.StartGrab(grabber); if (_rigidbody) { _rigidbody.useGravity = false; } }
protected override void AttachToGrabber(BaseGrabber grabber) { GetComponent <Rigidbody>().isKinematic = true; if (!activeGrabbers.Contains(grabber)) { activeGrabbers.Add(grabber); } }
protected override void DetachFromGrabber(BaseGrabber grabber) { if (_rigidbody == null) { _rigidbody = GetComponent <Rigidbody>(); } _rigidbody.isKinematic = false; _rigidbody.useGravity = true; }
protected override void StartGrab(BaseGrabber grabber) { base.StartGrab(grabber); transform.position = new Vector3(0, 0, 0); Debug.Log(transform.position); transform.SetParent(grabber.GrabHandle); gameObject.GetComponent <Rigidbody>().isKinematic = true; transform.rotation = transform.parent.rotation; Debug.Log(transform.position); }
protected override void DetachFromGrabber(BaseGrabber grabber) { if (_rigidbody == null) { _rigidbody = GetComponent <Rigidbody>(); } _rigidbody.isKinematic = false; _rigidbody.useGravity = true; EatEnemies.Instance.RemoveEnemyFromList(gameObject); }
protected override void DetachFromGrabber(BaseGrabber grabber) { base.DetachFromGrabber(grabber); SpringJoint joint = gameObject.GetComponent <SpringJoint>(); if (joint != null) { joint.connectedBody = null; //Destroy(joint); StartCoroutine(DestroyJointAfterDelay(joint)); } }
protected override void DetachFromGrabber(BaseGrabber grabber) { base.DetachFromGrabber(grabber); FixedJoint joint = GetComponent <FixedJoint>(); if (joint != null) { joint.connectedBody = null; //DestroyImmediate(joint); StartCoroutine(DestroyJointAfterDelay(joint)); } }
protected override void StartGrab(BaseGrabber grabber) { base.StartGrab(grabber); if (this.gameObject.tag == "sticky") { SendMessage("Disconnecting"); Destroy(GetComponent <FixedJoint>()); } transform.SetParent(GrabberPrimary.transform); gameObject.GetComponent <Rigidbody>().isKinematic = true; }
protected override void AttachToGrabber(BaseGrabber grabber) { base.AttachToGrabber(grabber); FixedJoint joint = GetComponent <FixedJoint>(); if (joint == null) { joint = gameObject.AddComponent <FixedJoint>(); } joint.connectedBody = grabber.GetComponent <Rigidbody>(); joint.anchor = jointAnchor; joint.breakForce = breakForce; joint.breakTorque = breakTorque; }
protected override void AttachToGrabber(BaseGrabber grabber) { base.AttachToGrabber(grabber); SpringJoint joint = gameObject.GetComponent <SpringJoint>(); if (joint == null) { joint = gameObject.AddComponent <SpringJoint>(); } joint.connectedBody = grabber.GetComponent <Rigidbody>(); joint.anchor = new Vector3(0, 0.01f, 0.01f); joint.tolerance = tolerance; joint.breakForce = breakForce; joint.breakTorque = breakTorque; joint.spring = spring; joint.damper = damper; }
// The next two functions provide basic behaviour. Extend from this base script in order to provide more specific functionality. protected override void AttachToGrabber(BaseGrabber grabber) { if (_rigidbody == null) { _rigidbody = GetComponent <Rigidbody>(); } _rigidbody.isKinematic = true; if (!activeGrabbers.Contains(grabber)) { activeGrabbers.Add(grabber); } DestroyEnemyUnit destroyEnemyScript = GetComponent <DestroyEnemyUnit>(); destroyEnemyScript.ChangeStateToDestroyed(Vector3.zero); EatEnemies.Instance.AddEnemyToList(gameObject); }
protected virtual void StartGrab(BaseGrabber grabber) { Debug.Log("Start grab"); if (GrabState == GrabStateEnum.Inactive) { Debug.Log("State is inactive"); // If we're not already updating our grab state, start now activeGrabbers.Add(grabber); StartCoroutine(StayGrab()); } else { Debug.Log("State is not inactive"); // Otherwise just push the grabber activeGrabbers.Add(grabber); } // Attach ourselves to this grabber AttachToGrabber(grabber); if (OnGrabbed != null) { OnGrabbed(this); } }
/// <summary> /// Removes a grabber object from the list of available grabbers /// </summary> public void RemoveContact(BaseGrabber availableObject) { availableGrabbers.Remove(availableObject); }
protected override void DetachFromGrabber(BaseGrabber grabber) { base.DetachFromGrabber(grabber); rb.useGravity = true; }
protected override void AttachToGrabber(BaseGrabber grabber) { base.AttachToGrabber(grabber); rb.useGravity = false; }
protected override void DetachFromGrabber(BaseGrabber grabber) { GetComponent <Rigidbody>().isKinematic = false; GetComponent <Rigidbody>().useGravity = true; }
protected virtual void DetachFromGrabber(BaseGrabber grabber) { // By default this does nothing // In most cases this will un-parent or destroy a joint }
/// <summary> /// Attempts to transfer ownership of grabbable object to another grabber /// Can override to 'lock' objects to a grabber, if desired /// </summary> /// <param name="ownerGrab"></param> /// <param name="otherGrabber"></param> /// <returns></returns> public virtual bool CanTransferOwnershipTo(BaseGrabbable ownerGrab, BaseGrabber otherGrabber) { Debug.Log("Transferring ownership of " + ownerGrab.name + " to grabber " + otherGrabber.name); grabbedObjects.Remove(ownerGrab); return(true); }
/// <summary> /// Adds a grabber object to the list of available grabbers /// </summary> public void AddContact(BaseGrabber availableObject) { availableGrabbers.Add(availableObject); }
// The next three functions provide basic behavior. Extend from this base script in order to provide more specific functionality. protected virtual void AttachToGrabber(BaseGrabber grabber) { // By default this does nothing // In most cases this will parent or create a joint }
protected override void DetachFromGrabber(BaseGrabber grabber) { Debug.Log("Detaching form grabber"); }