public void HorizontalMovement(InteractionInformation interactionInformation)
        {
            if (!horizontalMovementEnabled)
            {
                return;
            }
            Vector2 input = interactionInformation.JoystickPosition;

            Vector3 forward = _camera.transform.forward;

            forward.y = 0f;
            forward.Normalize();
            Vector3 right = _camera.transform.right;

            right.y = 0f;
            right.Normalize();

            Vector3 coordinates = right * input.x + forward * input.y;

            // Respecting colliders

            if (respectColliders)
            {
                Vector3 cameraPosition = _camera.transform.position;

                // walls
                Ray raycast = new Ray(cameraPosition, coordinates);
                if (Physics.SphereCast(raycast, .1f, .5f))
                {
                    return;
                }

                // slanted surfaces / stairs
                Vector3 movementPoint = new Vector3(coordinates.x, transform.position.y, coordinates.z);
                Vector3 onTheGround   = new Vector3(movementPoint.x / 2f, movementPoint.y - cameraPosition.y,
                                                    movementPoint.z / 2f);

                float cameraHeight = _camera.transform.localPosition.y;

                Ray surfaceRay = new Ray(cameraPosition, onTheGround);

                Physics.SphereCast(surfaceRay, .1f, out RaycastHit hit);

                float difference = cameraHeight - hit.distance;

                if (Math.Abs(difference) >= colliderDifferenceThreshold && hit.point != Vector3.zero)
                {
                    coordinates = new Vector3(coordinates.x, coordinates.y + difference, coordinates.z);
                    if (debugColliderDifference)
                    {
                        Debug.DrawRay(cameraPosition, onTheGround, Color.red, 1000);
                        Debug.Log(difference);
                    }
                }
            }

            transform.Translate(coordinates * movementSpeed * Time.deltaTime);
        }
        private void FireInputHandler(ControllerInput input, InteractionInformation interactionInformation)
        {
            var triggerClicks = _view.InputBindings.Where(x => x.input == input);

            foreach (var inputBinding in triggerClicks)
            {
                inputBinding.axisHandler?.Invoke(interactionInformation);
            }
        }
        public void VerticalMovement(InteractionInformation interactionInformation)
        {
            if (!verticalMovementEnabled)
            {
                return;
            }
            Vector2 input       = interactionInformation.JoystickPosition;
            Vector3 coordinates = Vector3.up * input.y;

            if (_camera.transform.position.y > (floorLevel + .5f) || input.y > 0)
            {
                transform.Translate(coordinates * movementSpeed * Time.deltaTime);
            }
        }
Exemplo n.º 4
0
 public PlayerHandInputDevice(HumanBodyPart part, XrGeneralSettings settings)
 {
     TrackingInformation    = new TrackingInformation(part);
     InteractionInformation = new InteractionInformation(part, settings);
 }