Exemple #1
0
        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.ControllerByIndex(controllerIndex);

                if (device)
                {
                    velocity = -device.GetComponent <VRTK_ControllerEvents>().GetVelocity();
                    if (usePlayerScale)
                    {
                        velocity = Vector3.Scale(velocity, transform.localScale);
                    }
                }

                playerPresence.StartPhysicsFall(velocity);
            }
            climbingObject = null;
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
        private void DropToNearestFloor(bool withBlink, bool useGravityFall)
        {
            if (enableTeleport && eyeCamera.transform.position.y > transform.position.y)
            {
                //send a ray down to find the closest object to stand on
                Ray        ray = new Ray(eyeCamera.transform.position, -transform.up);
                RaycastHit rayCollidedWith;
                bool       rayHit = Physics.Raycast(ray, out rayCollidedWith);
                float      floorY = eyeCamera.transform.position.y - rayCollidedWith.distance;

                if (rayHit && ValidLocation(rayCollidedWith.transform, rayCollidedWith.point) && !FloorIsGrabbedObject(rayCollidedWith))
                {
                    var floorDelta = currentRayDownY - floorY;
                    currentFloor    = rayCollidedWith.transform.gameObject;
                    currentRayDownY = floorY;

                    float fallDistance        = transform.position.y - floorY;
                    bool  shouldDoGravityFall = useGravityFall && (playerPresence.IsFalling() || fallDistance > gravityFallHeight);

                    if (withBlink && !shouldDoGravityFall && (floorDelta > blinkYThreshold || floorDelta < -blinkYThreshold))
                    {
                        Blink(blinkTransitionSpeed);
                    }

                    if (floorY != previousFloorY)
                    {
                        if (shouldDoGravityFall)
                        {
                            playerPresence.StartPhysicsFall(Vector3.zero);
                        }
                        else // teleport fall
                        {
                            Vector3 newPosition  = new Vector3(transform.position.x, floorY, transform.position.z);
                            var     teleportArgs = new DestinationMarkerEventArgs
                            {
                                destinationPosition = newPosition,
                                distance            = rayCollidedWith.distance,
                                enableTeleport      = true,
                                target = currentFloor.transform
                            };
                            OnTeleporting(gameObject, teleportArgs);
                            SetNewPosition(newPosition, currentFloor.transform);
                            OnTeleported(gameObject, teleportArgs);
                        }
                    }
                }
                previousFloorY = floorY;
            }
        }
Exemple #4
0
        private void Ungrab(bool carryMomentum, uint controllerIndex, GameObject target)
        {
            OnPlayerClimbEnded(SetPlayerClimbEvent(controllerIndex, target));
            isClimbing = false;

            // Move to the last safe spot
            if (headsetColliding)
            {
                transform.position = lastGoodHeadsetPosition;
            }

            if (useGravity && carryMomentum)
            {
                var device = VRTK_DeviceFinder.ControllerByIndex(controllerIndex);
                playerPresence.StartPhysicsFall(-device.GetComponent <VRTK_ControllerEvents>().GetVelocity());
            }
        }
Exemple #5
0
        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      floorY = eyeCamera.transform.position.y - rayCollidedWith.distance;

                if (ValidDrop(rayHit, rayCollidedWith, floorY))
                {
                    if (UsePhysicsFall(useGravityFall, floorY))
                    {
                        playerPresence.StartPhysicsFall(Vector3.zero);
                    }
                    else
                    {
                        TeleportFall(withBlink, floorY, rayCollidedWith);
                    }
                }
                previousFloorY = floorY;
            }
        }