Esempio n. 1
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;
            }
        }
Esempio n. 2
0
        private bool UsePhysicsFall(bool useGravityFall, float floorY)
        {
            float fallDistance = transform.position.y - floorY;

            return(useGravityFall && (playerPresence.IsFalling() || fallDistance > gravityFallHeight));
        }