protected virtual IEnumerator lerpToPosition(object sender, DestinationMarkerEventArgs e, Vector3 startPosition, Vector3 targetPosition, Quaternion startRotation, Quaternion targetRotation) { enableTeleport = false; bool gameObjectInTheWay = false; // Find the objects we will be dashing through and broadcast them via events Vector3 eyeCameraPosition = headset.transform.position; Vector3 eyeCameraPositionOnGround = new Vector3(eyeCameraPosition.x, playArea.position.y, eyeCameraPosition.z); Vector3 eyeCameraRelativeToRig = eyeCameraPosition - playArea.position; Vector3 targetEyeCameraPosition = targetPosition + eyeCameraRelativeToRig; Vector3 direction = (targetEyeCameraPosition - eyeCameraPosition).normalized; Vector3 bottomPoint = eyeCameraPositionOnGround + (Vector3.up * capsuleBottomOffset) + direction; Vector3 topPoint = eyeCameraPosition + (Vector3.up * capsuleTopOffset) + direction; float maxDistance = Vector3.Distance(playArea.position, targetPosition - direction * 0.5f); RaycastHit[] allHits = Physics.CapsuleCastAll(bottomPoint, topPoint, capsuleRadius, direction, maxDistance); for (int i = 0; i < allHits.Length; i++) { gameObjectInTheWay = (allHits[i].collider.gameObject != e.target.gameObject ? true : false); } if (gameObjectInTheWay) { OnWillDashThruObjects(SetDashTeleportEvent(allHits)); } lerpTime = (maxDistance >= minDistanceForNormalLerp ? normalLerpTime : VRTK_SharedMethods.DividerToMultiplier(minSpeedMps) * maxDistance); float elapsedTime = 0f; float currentLerpedTime = 0f; WaitForEndOfFrame delayInstruction = new WaitForEndOfFrame(); while (currentLerpedTime < 1f) { playArea.position = Vector3.Lerp(startPosition, targetPosition, currentLerpedTime); playArea.rotation = Quaternion.Lerp(startRotation, targetRotation, currentLerpedTime); OnTeleported(sender, e);//mine elapsedTime += Time.deltaTime; currentLerpedTime = elapsedTime / lerpTime; yield return(delayInstruction); } playArea.position = targetPosition; playArea.rotation = targetRotation; if (gameObjectInTheWay) { OnDashedThruObjects(SetDashTeleportEvent(allHits)); } base.EndTeleport(sender, e); gameObjectInTheWay = false; enableTeleport = true; }
protected virtual void SetObjects(Material material, Color color) { float stepSize = frequency * 1; if (Loop || stepSize == 1) { stepSize = VRTK_SharedMethods.DividerToMultiplier(stepSize); } else { stepSize = VRTK_SharedMethods.DividerToMultiplier((stepSize - 1)); } SetPointData(material, color, stepSize); }
public virtual Vector3[] GetPoints(Vector3[] controlPoints) { PointsInit(controlPoints); Vector3[] calculatedPoints = new Vector3[frequency]; float stepSize = frequency * 1; if (Loop || stepSize == 1) { stepSize = VRTK_SharedMethods.DividerToMultiplier(stepSize); } else { stepSize = VRTK_SharedMethods.DividerToMultiplier((stepSize - 1)); } for (int f = 0; f < frequency; f++) { calculatedPoints[f] = GetPoint(f * stepSize); } return(calculatedPoints); }