Пример #1
0
    /// <summary>
    /// This function handles the Point of interest gaze movement,
    /// by shooting ray and check the hit on POI layer.
    /// When hits and calculates the distance of target.
    /// If hits and not too close invokes some events,
    /// and if using controllers check controller primary input to call function Move Towards Point.
    /// else if not using controllers call Move Towards Point on hmd primary button press
    /// </summary>
    public void POIGazeMovement()
    {
        RaycastHit hit;
        bool       hits = Physics.Raycast(control.rig.hmd.transform.position,
                                          control.rig.hmd.transform.forward,
                                          out hit,
                                          control.movementVariables.raycastDistance,
                                          control.movementVariables.POIMask);

        if (hits)
        {
            bool closeToTarget = Vector3.Distance(control.rig.hmd.position, hit.transform.position) < 0.5f;
            currentTarget = hit.transform;
            if (!closeToTarget)
            {
                if (!canMove)
                {
                    canMove = true;
                    onAbleToMove?.Invoke(hit.transform);
                    control.MoveLock(canMove);
                }
                if (control.usingControllers)
                {
                    if (control.rig.input.GetPrimaryButtonControlPress(control.preferredHand))
                    {
                        MoveTowardsPoint(hit.transform);
                    }
                }
                else
                {
                    if (control.rig.input.hmdPrimaryButtonPress)
                    {
                        MoveTowardsPoint(hit.transform);
                    }
                }
            }
            else
            {
                if (canMove)
                {
                    canMove = false;
                    onUnableToMove?.Invoke(hit.transform);
                    control.MoveLock(canMove);
                }
            }
        }
        else
        {
            if (canMove)
            {
                canMove = false;
                onUnableToMove?.Invoke(hit.transform);
            }
        }
    }
 /// <summary>
 /// This function is called,
 /// when LerpMovementTrigger on Waypoint Move event is invoked.
 /// Sets new target waypoint index.
 /// </summary>
 /// <param name="newWpIndex">new waypoint index</param>
 public void MoveTowardsWP(int newWpIndex)
 {
     Debug.Log(newWpIndex + " <= " + control.Wps.Length);
     if (newWpIndex <= control.Wps.Length)
     {
         control.movementVariables.lerpValue = 0f;
         currentWPIndex = newWpIndex;
         moving         = true;
         control.MoveLock(moving);
     }
 }
Пример #3
0
    /// <summary>
    /// This function checks the possibility of teleport with controllers,
    /// by raycasting and hitting only teleport layer.
    /// Also calls the events for teleport possibility
    /// for MoveEventListener to adjust the visual indicator.
    /// </summary>
    void WithControllers()
    {
        Transform c    = control.rig.GetControllerTransform(control.preferredHand);
        bool      hits = Physics.Raycast(c.position,
                                         c.forward,
                                         out hit,
                                         control.movementVariables.raycastDistance,
                                         control.movementVariables.raycastLayerMask);

        if (hits)
        {
            if (hit.transform.gameObject.layer == LayerMask.NameToLayer("TeleMask"))
            {
                onTeleportPossible?.Invoke(hit);
                if (!canTele)
                {
                    canTele = true;
                    control.MoveLock(canTele);
                }
            }
            else
            {
                if (canTele)
                {
                    canTele = false;
                    onTeleportNotPossible?.Invoke(hit);
                }
            }
        }
        else
        {
            if (canTele)
            {
                canTele = false;
                onTeleportNotPossible?.Invoke(hit);
                control.MoveLock(canTele);
            }
        }
    }
    /// <summary>
    /// This function handles the gazing,
    /// and checking the possibility of movement with transform eulerangles.
    /// When possible to move,
    /// calls the MoveToGazeDirection on continuous Primary Button press.
    /// Also invokes the events for other classes.
    /// For example on Correct Move Angle MoveEventListener to handle the visual.
    /// </summary>
    private void GazeMovement()
    {
        float xAngle = control.rig.hmd.transform.rotation.eulerAngles.x;

        bool moving = xAngle <control.movementVariables.gazeAngleMax && xAngle> control.movementVariables.gazeAngleMin;

        if (moving)
        {
            if (!canMove)
            {
                canMove = true;
                onCorrectMoveAngle?.Invoke(control.rig.hmd);
                control.MoveLock(canMove);
            }
            if (control.usingControllers)
            {
                if (control.rig.input.GetPrimaryButtonControlPress(control.preferredHand))
                {
                    MoveToGazeDirection();
                }
            }
            else
            {
                if (control.rig.input.hmdPrimaryButtonPress)
                {
                    MoveToGazeDirection();
                }
            }
        }
        else
        {
            if (canMove)
            {
                canMove = false;
                onNonCorrectMoveAngle?.Invoke(control.rig.hmd);
                control.MoveLock(canMove);
            }
        }
    }