예제 #1
0
    void OnTriggerStay(Collider coll)
    {
        if (coll.gameObject.tag == "GazeRadius")
        {
            gazeRadius = coll.gameObject;                       //get the sphere collider around the player

            if (GameMaster.Biofeedback())
            {
                boxAnimator.SetBool("hasGaze", _gazeAware.HasGazeFocus);                    //makes it so the box's eye will open up when has gaze
                if (_gazeAware.HasGazeFocus)
                {
                    if (player == null)
                    {
                        FindPlayer();                                           //only find the player if it's null
                    }

                    gazePoint = TobiiAPI.GetGazePoint();

                    if (Input.GetAxis(ControllerInputManager.Grab()) > 0 && player != null)
                    {
                        float radius = gazeRadius.GetComponent <SphereCollider>().radius;

                        //sets the cube's pos to gaze pos; converts screen space to world space
                        transform.position = Camera.main.ScreenToWorldPoint(gazePoint.Screen);

                        Vector3 centerPt = player.GetComponentInChildren <SphereCollider>().transform.position;

                        float distance = Vector3.Distance(Camera.main.ScreenToWorldPoint(gazePoint.Screen), centerPt);

                        if (distance > radius)                                                                                      //if distance becomes greater than radius
                        {
                            Vector3 newPos = transform.position - centerPt;                                                         //create vector of difference of cube pos and center pos
                            newPos            *= radius / distance;                                                                 //calc position in circle around center pos
                            transform.position = centerPt + newPos;                                                                 //sets cubes pos to the max distance away from center pos
                            box.velocity       = (transform.position - box.transform.position) * 10;                                //uses box's physics to move along with cube's movements
                            transform.position = box.transform.position;                                                            //this prevents the box from moving into the ground
                        }
                        else
                        {
                            box.velocity       = (transform.position - box.transform.position) * 10;
                            transform.position = box.transform.position;                                                                //anchors 3D collider to the box so they always stay together
                            //Debug.Log ("transform: " + transform.position);
                        }
                    }
                }
            }
            else
            {
            }
        }
    }
예제 #2
0
    private void OnTriggerStay2D(Collider2D coll)
    {
        if (!GameMaster.Biofeedback())
        {
            if (coll.gameObject.tag == "GazeRadius")
            {
                gazeRadius = coll.gameObject.GetComponent <CircleCollider2D>();
            }

            if (coll.gameObject.tag == "gaze_pt")
            {
                if (player == null)
                {
                    FindPlayer();                                       //only find the player if it's null
                }

                if (Input.GetAxis(ControllerInputManager.Grab()) > 0 && player != null)
                {
                    boxAnimator.SetBool("hasGaze", true);
                    float radius = gazeRadius.radius;
                    transform.position = player.pointer.transform.position;
                    Vector3 centerPt = player.GetComponentInChildren <CircleCollider2D>().transform.position;

                    float distance = Vector3.Distance(player.pointer.transform.position, centerPt);

                    if (distance > radius)                                                                                  //if distance becomes greater than radius
                    {
                        Vector3 newPos = transform.position - centerPt;                                                     //create vector of difference of cube pos and center pos
                        newPos            *= radius / distance;                                                             //calc position in circle around center pos
                        transform.position = centerPt + newPos;                                                             //sets cubes pos to the max distance away from center pos
                        box.velocity       = (transform.position - box.transform.position) * 10;
                        transform.position = box.transform.position;
                    }
                    else
                    {
                        box.velocity       = (transform.position - box.transform.position) * 10;
                        transform.position = box.transform.position;
                    }
                }
                else
                {
                    boxAnimator.SetBool("hasGaze", false);
                }
            }
        }
    }
예제 #3
0
    /*
     * Updates the GazePoint so all methods in this class can access its position.
     */
    protected override void GetGaze()
    {
        FallingOutOfBounds();

        if (Input.GetKeyDown(KeyCode.U))
        {
            GameMaster.AddToJoy(100);
            GameMaster.AddToAnger(100);
        }

        if (biofeedback)
        {
            gazePoint = TobiiAPI.GetGazePoint();
        }

        if (Input.GetAxis(ControllerInputManager.Grab()) > 0)
        {
            pointerAni.SetBool("holdL", true);
            gazeUIAni.SetBool("holdL", true);
            Vector3 centerPt;
            float   radius;
            float   distance;

            //if using biofeedback, will set pointer to gaze positions
            if (biofeedback)
            {
                gaze = Camera.main.ScreenToWorldPoint(gazePoint.Screen);

                centerPt = GetComponentInChildren <SphereCollider>().transform.position;
                radius   = GetComponentInChildren <SphereCollider>().radius;

                distance = Vector3.Distance(Camera.main.ScreenToWorldPoint(gazePoint.Screen), centerPt);

                if (distance > radius)
                {
                    Vector3 newPos = transform.position - centerPt;
                    newPos *= radius / distance;
                    pointer.transform.position = centerPt + newPos;
                }
                else
                {
                    pointer.transform.position = gaze;
                }
            }
            else
            {
                //else will move via analog stick movement
                pointer.transform.position += new Vector3(15 * Input.GetAxis("PS4_RightAnalogHorizontal"),
                                                          -15 * Input.GetAxis("PS4_RightAnalogVertical"), 0);

                centerPt = GetComponentInChildren <CircleCollider2D>().transform.position;
                radius   = GetComponentInChildren <CircleCollider2D>().radius;
                distance = Vector3.Distance(pointer.transform.position, centerPt);

                if (distance > radius)
                {
                    Vector3 newPos = pointer.transform.position - centerPt;
                    newPos *= radius / distance;

                    pointer.transform.position = centerPt + newPos;
                }
            }
        }
        else
        {
            if (pointer != null)
            {
                pointerAni.SetBool("holdL", false);
            }
            gazeUIAni.SetBool("holdL", false);
        }
    }