// Update is called once per frame
    void Update()
    {
        user_position.x = transform.position.x;
        user_position.y = transform.position.z;

        //get the local rotation (in terms of the room) and set the rotation of the character
        user_localRotation = UserRotation.GetRotation();
        transform.rotation = Quaternion.Euler(0, user_localRotation, 0);

        //store where the user is facing
        user_forward = transform.forward;

        //if user presses button, the user reached the current target

        /*if (Input.GetKeyDown(KeyCode.Space))
         *  NextTarget();*/

        if (Input.GetButtonDown("Fire2"))
        {
            NextTarget();
        }
    }
Exemplo n.º 2
0
    IEnumerator UpdatePositionAndRotation()
    {
        while (true)
        {
            //auto move the player through the environment (used for testing)
            if (auto_move)
            {
                nextposition = path[curwaypointindex].transform.position;
                //move to the next target
                while ((transform.position - nextposition).sqrMagnitude > .1f)
                {
                    //rotate towards the next target

                    //float angle = Vector3.SignedAngle((nextposition - transform.position).normalized, transform.forward, Vector3.up);
                    //if ( angle > 1f)
                    //{
                    //    FindObjectOfType<Notification_Voice>().Speak(VoiceDirection.Left);
                    //}
                    //else if (angle < -1f)
                    //{
                    //    FindObjectOfType<Notification_Voice>().Speak(VoiceDirection.Right);
                    //}


                    while (Vector3.SignedAngle((nextposition - transform.position).normalized, transform.forward, Vector3.up) > 1)
                    {
                        transform.Rotate(0, -auto_rotation.value * Time.deltaTime * 20, 0);
                        SetMyValues();
                        yield return(null);
                    }
                    while (Vector3.SignedAngle((nextposition - transform.position).normalized, transform.forward, Vector3.up) < -1)
                    {
                        transform.Rotate(0, auto_rotation.value * Time.deltaTime * 20, 0);
                        SetMyValues();
                        yield return(null);
                    }
                    transform.LookAt(nextposition);

                    transform.Translate((nextposition - transform.position).normalized * auto_speed.value * Time.deltaTime, Space.World);
                    SetMyValues();
                    yield return(null);
                }
                transform.position = nextposition;
            }
            else if (lock_move)
            {
                //get position from IndoorManager
                user_position.x = (float)IndoorManager.x;
                user_position.z = (float)IndoorManager.y;

                if (curwaypointindex >= 1)
                {
                    transform.position = Vector3.Lerp(transform.position, NearestPointOnLine(path[curwaypointindex - 1].transform.position, path[curwaypointindex].transform.position, user_position), .02f);
                }
                else
                {
                    transform.position = Vector3.Lerp(transform.position, user_position, .02f);
                }

                //get the local rotation (in terms of the room) and set the rotation of character
                user_localRotation = UserRotation.GetRotation();
                testing.text       = string.Format("Rot: {0:0.00}", user_localRotation);
                transform.rotation = Quaternion.Euler(0, user_localRotation, 0);

                //store where the user is facing
                user_forward = transform.forward;
            }
            //use estimote and phone rotation to move (used for deployment)
            else
            {
                //get position from IndoorManager
                user_position.x    = (float)IndoorManager.x;
                user_position.z    = (float)IndoorManager.y;
                transform.position = Vector3.Lerp(transform.position, user_position, .02f);

                //get the local rotation (in terms of the room) and set the rotation of character
                user_localRotation = UserRotation.GetRotation();
                testing.text       = string.Format("Rot: {0:0.00}", user_localRotation);
                transform.rotation = Quaternion.Euler(0, user_localRotation, 0);

                //store where the user is facing
                user_forward = transform.forward;
            }
            yield return(null);
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        //  user_position.x = transform.position.x;
        // user_position.y = transform.position.z;


        if (!lookingAtNextCheckpoint)
        {
            if (Input.GetKey(KeyCode.D))
            {
                keyRot += 10f;
            }
            else if (Input.GetKey(KeyCode.A))
            {
                keyRot -= 10f;
            }

            user_localRotation = UserRotation.GetRotation();
        }


        if (!instruction.isPlaying)
        {
    #if UNITY_EDITOR
            transform.rotation = Quaternion.Euler(0, keyRot, 0);
#else
            transform.rotation = Quaternion.Euler(0, user_localRotation, 0);
#endif
        }

        Vector3 distance = transform.position - curWaypoint.transform.position;

        if (lookingAtNextCheckpoint && lockRotation)
        {
            transform.position = Vector3.MoveTowards(transform.position, curWaypoint.transform.position, Time.deltaTime * slider.value * speed);
        }

        if (distance.sqrMagnitude == 0f)
        {
            lockRotation = false;
            curWaypoint.Hide();
            curwaypointindex++;
            if (curwaypointindex > path.Length - 1)
            {
                Debug.Log("Out of waypoint");
                instruction.PlayInstruction(InstructionType.Complete);
                tutorialOver = true;
                voice.Stop();
                curwaypointindex = 0;

                StopCoroutine("IReload");
                StartCoroutine("IReload");
            }
            curWaypoint = path[curwaypointindex];
            targetObj.transform.position = path[curwaypointindex].transform.position;
            if (lookingAtNextCheckpoint)
            {
                distance = transform.position - curWaypoint.transform.position;
            }
        }

        lookingAtNextCheckpoint = Vector3.Angle(transform.position - curWaypoint.transform.position, -transform.forward) < 10;

        if (lockRotation == false)
        {
            if (lookingAtNextCheckpoint)
            {
                lockRotation = true;
            }
        }

        curWaypoint.Show();

        if (lockRotation)
        {
            transform.LookAt(curWaypoint.transform.position);
        }

        PlayVoice();
    }