Beispiel #1
0
        private void FixedUpdate()
        {
            if (_waitingForHMDActive)
            {
                return;
            }

            if (_waitingForCameraMovement)
            {
                if (Camera.localPosition == Vector3.zero)
                {
                    return;
                }

                var delta = Camera.transform.position - CharacterController.transform.position;
                delta.y = 0f;
                if (delta.magnitude > 0.0f)
                {
                    CharacterController.Move(-delta);
                }
                _waitingForCameraMovement = false;
            }



            if (CharacterController.enabled)
            {
                if (MovementEnabled)
                {
                    HandleMovement();
                }

                if (RotationEnabled)
                {
                    HandleRotation();
                }
            }

            CheckLean();
            CheckGrounded();

            if (Quaternion.Angle(transform.rotation, _previousRotation) > 1f)
            {
                _timeSinceLastRotation = 0f;
            }
            else
            {
                _timeSinceLastRotation += Time.deltaTime;
            }



            if (_hasTeleporter)
            {
                if (_timeSinceLastRotation < RotationTeleportThreshold && !Teleporter.IsAiming ||
                    IsClimbing || !IsGrounded)
                {
                    Teleporter.Disable();
                }
                else
                {
                    Teleporter.Enable();
                }
            }

            _actualVelocity = ((transform.position - _previousPosition) / Time.deltaTime).magnitude;

            _previousLeftControllerPosition  = LeftControllerTransform.position;
            _previousRightControllerPosition = RightControllerTransform.position;
            _previousRotation = transform.rotation;
            _previousPosition = transform.position;
        }