private void Ungrab(bool carryMomentum, uint controllerIndex, GameObject target) { OnPlayerClimbEnded(SetPlayerClimbEvent(controllerIndex, target)); isClimbing = false; // Move to the last safe spot if (headsetColliding) { Vector3 headsetPosition = headCamera.transform.position; Vector3 moveVector = lastGoodHeadsetPosition - headsetPosition; Vector3 moveDirection = moveVector.normalized; Vector3 moveOffset = moveDirection * safeZoneTeleportOffset; transform.position += moveVector + moveOffset; } if (useGravity && carryMomentum) { Vector3 velocity = Vector3.zero; var device = VRTK_DeviceFinder.TrackedObjectByIndex(controllerIndex); if (device) { velocity = -device.GetComponent <VRTK_ControllerEvents>().GetVelocity(); if (usePlayerScale) { velocity = Vector3.Scale(velocity, transform.localScale); } } playerPresence.StartPhysicsFall(velocity); } climbingObject = null; }
private void DropToNearestFloor(bool withBlink, bool useGravityFall) { if (enableTeleport && eyeCamera.transform.position.y > transform.position.y) { Ray ray = new Ray(eyeCamera.transform.position, -transform.up); RaycastHit rayCollidedWith; bool rayHit = Physics.Raycast(ray, out rayCollidedWith); float hitFloorY = eyeCamera.transform.position.y - rayCollidedWith.distance; if (ValidDrop(rayHit, rayCollidedWith, hitFloorY)) { if (initialFloorDrop && hitFloorY < previousFloorY && ControllersStillOverPreviousFloor()) { return; } if (UsePhysicsFall(useGravityFall, hitFloorY)) { playerPresence.StartPhysicsFall(Vector3.zero); } else { TeleportFall(withBlink, hitFloorY, rayCollidedWith); } initialFloorDrop = true; } previousFloorY = hitFloorY; } }