/// <summary> /// A coroutine that moves the camera rig to the teleport location over time. /// </summary> /// <returns></returns> private IEnumerator Move() { if (teleportStatus == TeleportStatus.Moving) { yield break; } teleportStatus = TeleportStatus.Moving; VirtualFollower head = PuppetJumpManager.Instance.puppetRig.GetComponent <PuppetRigVR>().virtualFollowers.head; float i = 0; float rate = 1 / teleportSpeed; while (i < 1) { teleportStatus = TeleportStatus.Moving; i += rate * Time.deltaTime; PuppetJumpManager.Instance.puppetRig.transform.position = Vector3.Lerp(initialPos, finalPos, teleportCurve.Evaluate(i)); // update the height and center charcater controller float newHeight = head.transform.localPosition.y; PuppetJumpManager.Instance.puppetRig.characterController.height = newHeight; Vector3 newCenter = PuppetJumpManager.Instance.puppetRig.characterController.center; newCenter = new Vector3(head.transform.localPosition.x, PuppetJumpManager.Instance.puppetRig.transform.position.y + (newHeight * 0.5f), head.transform.localPosition.z); PuppetJumpManager.Instance.puppetRig.characterController.center = newCenter; yield return(null); } teleportStatus = TeleportStatus.Idle; }
/// <summary> /// Used to position, or begin the moving of, the puppetRig to the teleport location. /// </summary> public virtual void Teleport() { //move the camera rig to the position of the teleport teleportLoc = teleportTo; setView = PuppetJumpManager.Instance.puppetRig.views.view; float saveRot = cameraRig.cam.transform.eulerAngles.y; // store the positio and rotation of the cameraRig rigPos = cameraRig.transform.position; rigRot = cameraRig.transform.rotation; // the user is immediately placed in the teleport location if (setView != PuppetRig.ViewTypes.firstPerson) { // switch to first person PuppetJumpManager.Instance.puppetRig.SetView(PuppetRig.ViewTypes.firstPerson); } // adjust to allow for the offset of the camera inside the camera rig teleportLoc.x = teleportTo.x - (cameraRig.cam.transform.position.x - cameraRig.transform.position.x); teleportLoc.z = teleportTo.z - (cameraRig.cam.transform.position.z - cameraRig.transform.position.z); // since we switched to first person to determine the final position of the teleport if (setView != PuppetRig.ViewTypes.firstPerson) { // switch it back to the set view PuppetJumpManager.Instance.puppetRig.SetView(setView, rigPos, rigRot); } VirtualFollower head = PuppetJumpManager.Instance.puppetRig.GetComponent <PuppetRigVR>().virtualFollowers.head; if (instantTeleport) { // move instantly to the new position PuppetJumpManager.Instance.puppetRig.transform.position = teleportLoc; // update the height and center charcater controller float newHeight = head.transform.localPosition.y; PuppetJumpManager.Instance.puppetRig.characterController.height = newHeight; Vector3 newCenter = PuppetJumpManager.Instance.puppetRig.characterController.center; newCenter = new Vector3(head.transform.localPosition.x, PuppetJumpManager.Instance.puppetRig.transform.position.y + (newHeight * 0.5f), head.transform.localPosition.z); PuppetJumpManager.Instance.puppetRig.characterController.center = newCenter; } else { // kill any currently running move coroutine StopCoroutine(move); // get the current position of the puppetRig initialPos = PuppetJumpManager.Instance.puppetRig.transform.position; // set the final position of the puppetRig after the teleport finalPos = teleportLoc; // set and start the new move coroutine move = Move(); StartCoroutine(move); } //game object of the last telport teleportToGO_last = teleportToGO_hit; }