virtual public void Drop(bool addControllerVelocity, VRInteractor hand = null) { if (canBeHeld && item != null) { if (hand != null) { NetworkIdentity ident = item.GetComponent <NetworkIdentity>(); if (ident != null) { NetworkedCameraRig networkedRig = hand.GetVRRigRoot.GetComponent <NetworkedCameraRig>(); if (networkedRig != null && networkedRig.connection != null && networkedRig.connection.isLocalPlayer) { ident.RemoveClientAuthority(networkedRig.connection.connectionToClient); } } } item.parent = null; switch (holdType) { case HoldType.FIXED_POSITION: case HoldType.PICKUP_POSITION: VRInteractableItem.UnFreezeItem(item.gameObject); if (_selfBody != null && addControllerVelocity) { if (hand != null) { bool useBoost = hand.Velocity.magnitude > 1f; _selfBody.velocity = hand.Velocity * (useBoost ? throwBoost : 1f); _selfBody.angularVelocity = hand.AngularVelocity; _selfBody.maxAngularVelocity = _selfBody.angularVelocity.magnitude; } } break; case HoldType.SPRING_JOINT: for (int i = _heldBys.Count - 1; i >= 0; i--) { if (_heldBys[i] != hand) { continue; } _heldBys.RemoveAt(i); Destroy(_springJoints[i]); _springJoints.RemoveAt(i); } Rigidbody controllerBody = hand.getControllerAnchorOffset.GetComponent <Rigidbody>(); if (controllerBody != null) { Destroy(controllerBody); } break; } PlaySound(dropSound); } CheckIK(false, hand); if (dropEvent != null) { dropEvent.Invoke(); } heldBy = null; }
virtual public bool Pickup(VRInteractor hand) { if (canBeHeld && item != null) { NetworkIdentity ident = item.GetComponent <NetworkIdentity>(); if (ident != null) { NetworkedCameraRig networkedRig = hand.GetVRRigRoot.GetComponent <NetworkedCameraRig>(); if (networkedRig != null && networkedRig.connection != null && networkedRig.connection.isLocalPlayer) { ident.AssignClientAuthority(networkedRig.connection.connectionToClient); } } switch (holdType) { case HoldType.FIXED_POSITION: item.SetParent(hand.GetVRRigRoot); StartCoroutine(PickingUp(hand)); VRInteractableItem.HeldFreezeItem(item.gameObject); break; case HoldType.PICKUP_POSITION: if (Vector3.Distance(hand.getControllerAnchorOffset.position, item.position) < interactionDistance) { heldPosition = hand.getControllerAnchorOffset.InverseTransformPoint(item.position); } else { heldPosition = Vector3.zero; } heldRotation = Quaternion.Inverse(hand.getControllerAnchorOffset.rotation) * item.rotation; item.SetParent(hand.GetVRRigRoot); StartCoroutine(PickingUp(hand)); VRInteractableItem.HeldFreezeItem(item.gameObject); break; case HoldType.SPRING_JOINT: SpringJoint springJoint = item.gameObject.AddComponent <SpringJoint>(); Rigidbody controllerBody = hand.getControllerAnchorOffset.GetComponent <Rigidbody>(); if (controllerBody == null) { controllerBody = hand.getControllerAnchorOffset.gameObject.AddComponent <Rigidbody>(); } controllerBody.isKinematic = true; controllerBody.useGravity = false; springJoint.connectedBody = controllerBody; //springJoint.anchor = Vector3.zero; springJoint.anchor = item.InverseTransformPoint(hand.getControllerAnchorOffset.position); springJoint.autoConfigureConnectedAnchor = false; springJoint.connectedAnchor = Vector3.zero; springJoint.spring = followForce * 100f; springJoint.damper = 100f; _springJoints.Add(springJoint); _heldBys.Add(hand); break; } if (Vector3.Distance(hand.getControllerAnchorOffset.position, item.position) < interactionDistance) { PlaySound(pickupSound); } else { PlaySound(forceGrabSound, hand.getControllerAnchorOffset.position); } } if (pickupEvent != null) { pickupEvent.Invoke(); } CheckIK(true, hand); heldBy = hand; return(true); }