//public Transform stretchlessTarget; #region Init //public void Init(Transform targetTransform) { // handTarget = targetTransform.GetComponent<HandTarget>(); //} public override void Start(HumanoidControl humanoid, HumanoidTarget _target) { handTarget = (HandTarget)_target; if (handTarget.humanoid.avatarRig == null || handTarget.hand.bone.transform == null) { return; } if (humanoid.physics && handTarget.physics) { AdvancedHandPhysics physics = handTarget.hand.bone.transform.GetComponent <AdvancedHandPhysics>(); if (physics == null) { physics = handTarget.hand.bone.transform.gameObject.AddComponent <AdvancedHandPhysics>(); } physics.handTarget = handTarget; physics.mode = AdvancedHandPhysics.DeterminePhysicsMode(handTarget.handRigidbody, HandInteraction.kinematicMass); } else { BasicHandPhysics physics = handTarget.hand.bone.transform.GetComponent <BasicHandPhysics>(); if (physics == null) { physics = handTarget.hand.bone.transform.gameObject.AddComponent <BasicHandPhysics>(); } physics.handTarget = handTarget; } }
public virtual void Start() { if (!handTarget.physics) { AdvancedHandPhysics.SetKinematic(handTarget.handRigidbody); } }
public static void LocalGrab(HandTarget handTarget, GameObject obj, bool rangeCheck = true) { Rigidbody objRigidbody = obj.GetComponent <Rigidbody>(); Transform objTransform = obj.GetComponent <Transform>(); if (handTarget.grabbedObject == null) { if (objRigidbody != null) { NoGrab noGrab = objRigidbody.GetComponent <NoGrab>(); if (noGrab != null) { return; } } if (objRigidbody != null && objRigidbody.mass > maxGrabbingMass) { return; } bool grabbed = false; if (objRigidbody != null) { grabbed = GrabRigidbody(handTarget, objRigidbody, rangeCheck); } else { grabbed = GrabStaticObject(handTarget, objTransform, rangeCheck); } if (grabbed) { if (handTarget.humanoid.physics) { //HumanoidTarget.SetColliderToTrigger(handTarget.hand.bone.transform.gameObject, true); AdvancedHandPhysics.SetNonKinematic(handTarget.handRigidbody, handTarget.colliders); //handTarget.colliders = HumanoidTarget.SetColliderToTrigger(handTarget.hand.bone.transform.gameObject); if (handTarget.handPhysics != null && handTarget.handPhysics.mode != AdvancedHandPhysics.PhysicsMode.ForceLess) { handTarget.handPhysics.DeterminePhysicsMode(kinematicMass); } } handTarget.SendMessage("OnGrabbing", handTarget.grabbedObject, SendMessageOptions.DontRequireReceiver); handTarget.grabbedObject.SendMessage("OnGrabbed", handTarget, SendMessageOptions.DontRequireReceiver); } } }
public override void OnTriggerEnter(Collider collider) { bool otherHasKinematicPhysics = false; bool otherIsHumanoid = false; Rigidbody otherRigidbody = collider.attachedRigidbody; if (otherRigidbody != null) { AdvancedHandPhysics kp = otherRigidbody.GetComponent <AdvancedHandPhysics>(); otherHasKinematicPhysics = (kp != null); HumanoidControl humanoid = otherRigidbody.GetComponent <HumanoidControl>(); otherIsHumanoid = (humanoid != null); } if (handRigidbody != null && handRigidbody.isKinematic && (!collider.isTrigger || otherHasKinematicPhysics) && !otherIsHumanoid) { colliding = true; hasCollided = true; if (otherRigidbody != null) { handTarget.touchedObject = otherRigidbody.gameObject; SetNonKinematic(handRigidbody, handTarget.colliders); } else { handTarget.touchedObject = collider.gameObject; SetNonKinematic(handRigidbody, handTarget.colliders); } ProcessFirstCollision(handRigidbody, collider); } if (hasCollided) { Rigidbody objRigidbody = collider.attachedRigidbody; if (objRigidbody != null) { HandInteraction.GrabCheck(handTarget, objRigidbody.gameObject); } else { HandInteraction.GrabCheck(handTarget, collider.gameObject); } } }
public static void LocalLetGo(HandTarget handTarget) { //Debug.Log("LetGo"); if (handTarget.hand.bone.transform == null || handTarget.grabbedObject == null) { return; } if (handTarget.humanoid.physics) { AdvancedHandPhysics.SetNonKinematic(handTarget.handRigidbody, handTarget.colliders); } //AdvancedHandPhysics.SetKinematic(handTarget.handRigidbody, true); //handTarget.colliders = AdvancedHandPhysics.SetKinematic(handTarget.handRigidbody); Joint joint = handTarget.hand.bone.transform.GetComponent <Joint>(); if (joint != null) { LetGoJoint(handTarget, joint); } else { LetGoParenting(handTarget); } if (handTarget.humanoid.physics) { handTarget.colliders = AdvancedHandPhysics.SetKinematic(handTarget.handRigidbody); } if (handTarget.humanoid.dontDestroyOnLoad) { // Prevent this object inherites the dontDestroyOnLoad from the humanoid Object.DontDestroyOnLoad(handTarget.grabbedObject); } LetGoGrabbedObject(handTarget); }
public static bool GrabRigidbody(HandTarget handTarget, Rigidbody objRigidbody, bool rangeCheck = true) { //Debug.Log("GrabRigidbody"); return(false); if (objRigidbody == handTarget.otherHand.handRigidbody) { return(false); } if (handTarget.humanoid.humanoidNetworking != null) { handTarget.humanoid.humanoidNetworking.Grab(handTarget, objRigidbody.gameObject, rangeCheck); } GameObject obj = objRigidbody.gameObject; Handle[] handles = objRigidbody.GetComponentsInChildren <Handle>(); for (int i = 0; i < handles.Length; i++) { Vector3 handlePosition = handles[i].transform.TransformPoint(handles[i].position); float grabDistance = Vector3.Distance(handTarget.palmPosition, handlePosition); if ((handTarget.isLeft && handles[i].hand == Handle.Hand.Right) || (!handTarget.isLeft && handles[i].hand == Handle.Hand.Left)) { continue; } if (grabDistance < handles[i].range || !rangeCheck) { if (handles[i].grabType == Handle.GrabType.NoGrab) { return(false); } else { GrabRigidbodyHandle(handTarget, objRigidbody, handles[i]); handles[i].handTarget = handTarget; handTarget.grabbedObject = obj; return(true); } } } if (rangeCheck == false) { //float grabDistance = Vector3.Distance(handTarget.handPalm.position, objRigidbody.position); float grabDistance = Vector3.Distance(handTarget.hand.bone.transform.position, objRigidbody.position); if (grabDistance > 0.2F) // Object is far away, move it into the hand { MoveObjectToHand(handTarget, objRigidbody.transform); } } Joint joint = objRigidbody.GetComponent <Joint>(); AdvancedHandPhysics otherHandPhysics = objRigidbody.GetComponent <AdvancedHandPhysics>(); if (joint != null || objRigidbody.constraints != RigidbodyConstraints.None || otherHandPhysics != null) { GrabRigidbodyJoint(handTarget, objRigidbody); } else { GrabRigidbodyParenting(handTarget, objRigidbody); } handTarget.grabbedObject = obj; handTarget.grabbedRigidbody = true; return(true); }