Esempio n. 1
0
    void Update()
    {
        //If this is running in the unity editor or flagged as a development build set the gyroscope rotation values on the text objects
#if UNITY_EDITOR || DEVELOPMENT_BUILD
        if (SystemInfo.supportsGyroscope)
        {
            //Quaternion referenceRotation = Quaternion.identity;
            Quaternion deviceRotation = DeviceRotation.Get();
            //Vector3 modifier = new Vector3(0, 0, 1);
            //Quaternion modifiedRotation = Quaternion.Inverse(Quaternion.FromToRotation(referenceRotation * modifier, deviceRotation * modifier));
            //modifiedRotation *= deviceRotation;

            //float xVal = modifiedRotation.eulerAngles.x;
            //float yVal = modifiedRotation.eulerAngles.y;
            //float zVal = modifiedRotation.eulerAngles.z;
            float xVal = deviceRotation.eulerAngles.x;
            float yVal = deviceRotation.eulerAngles.y;
            float zVal = deviceRotation.eulerAngles.z;

            gyroX.text = ((xVal > 180f) ? ((treeInputMin / 180f) * (360f - xVal)) : ((treeInputMax / 180f) * xVal)).ToString();
            gyroY.text = ((yVal > 180f) ? ((treeInputMin / 180f) * (360f - yVal)) : ((treeInputMax / 180f) * yVal)).ToString();
            gyroZ.text = ((zVal > 180f) ? ((treeInputMin / 180f) * (360f - zVal)) : ((treeInputMax / 180f) * zVal)).ToString();

            //gyroX.text = modifiedRotation.eulerAngles.x.ToString();
            //gyroY.text = modifiedRotation.eulerAngles.y.ToString();
            //gyroZ.text = modifiedRotation.eulerAngles.z.ToString();
        }
#endif
    }
Esempio n. 2
0
    //required coz we don't control the spawning of networked objects in the scene.
    public void Start()
    {
        PlayerManager.Instance.gunner = this;
        transform.SetParent(PlayerManager.Instance.pilot.transform);
        gunBase           = transform.Find("Base"); //Base/ - for new prefab
        barrel            = gunBase.Find("Barrel");
        muzzle            = barrel.Find("Muzzle");
        CharStats         = new CharacterStats();
        previousGyroEuler = DeviceRotation.Get().eulerAngles;
        EndScreen         = GameObject.Find("EndScreen");
        GunnerCanvas      = GameObject.Find("GunnerCanvas");

        if (GunnerCanvas)
        {
            DynamicJoystick = GunnerCanvas.transform.Find("Dynamic Joystick").GetComponent <DynamicJoystick>();
            shootButton     = GunnerCanvas.transform.Find("Button").GetComponent <Button>();
            healthbar       = GunnerCanvas.transform.Find("DoubleBar").Find("lifeBar").GetComponent <Image>();
            shieldbar       = GunnerCanvas.transform.Find("DoubleBar").Find("shieldBar").GetComponent <Image>();

            shootButton.onClick.AddListener(onShootButton);
        }


        screenCenter = new Vector3(Screen.width / 2, Screen.height / 2, 0);
        mainCamera   = Camera.main;
    }
Esempio n. 3
0
 void GetOffset()
 {
     if (DeviceRotation.Get().ToString() != "(0.0, 0.0, 0.0, 0.0)" && !offset)
     {
         offsetRotation = Quaternion.Inverse(DeviceRotation.Get());
         offset         = true;
     }
 }
Esempio n. 4
0
    public static float WorldRotationAngleY()
    {
        Quaternion deviceRotation  = DeviceRotation.Get(0, 1, 0);
        Quaternion eliminationOfYZ = Quaternion.Inverse(
            Quaternion.FromToRotation(referenceRotation * Vector3.forward,
                                      deviceRotation * Vector3.forward)
            );
        Quaternion rotationZ = eliminationOfYZ * deviceRotation;

        return(rotationZ.eulerAngles.y);
    }
Esempio n. 5
0
    void Update()
    {
        Quaternion deviceRotation = DeviceRotation.Get();

        transform.rotation = deviceRotation;

        rb.AddForce(transform.forward * speed, ForceMode.Acceleration);

        rb.AddForce(transform.up * upSpeed, ForceMode.Acceleration);
        rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
    }
Esempio n. 6
0
    public static float StruisSpeedAngle()
    {
        Quaternion deviceRotation  = DeviceRotation.Get(0, 0, 1);
        Quaternion eliminationOfXY = Quaternion.Inverse(
            Quaternion.FromToRotation(referenceRotation * Vector3.forward,
                                      deviceRotation * Vector3.forward)
            );
        Quaternion rotationZ = eliminationOfXY * deviceRotation;

        return(rotationZ.eulerAngles.z);
    }
Esempio n. 7
0
    public float GetRotation()
    {
        Quaternion referenceRotation = Quaternion.identity;
        Quaternion deviceRotation    = DeviceRotation.Get();
        Quaternion eliminationOfXY   = Quaternion.Inverse(
            Quaternion.FromToRotation(referenceRotation * Vector3.forward,
                                      deviceRotation * Vector3.forward)
            );
        Quaternion rotationZ = eliminationOfXY * deviceRotation;
        float      roll      = rotationZ.eulerAngles.z;

        return(roll);
    }
Esempio n. 8
0
    void Update()
    {
        Console.Instance.ClearLog();
        GetOffset();

        Quaternion temp = DeviceRotation.Get();

        temp = offsetRotation * temp;
        SetRotation(temp);
        Console.Instance.Log("Device Rotation: " + DeviceRotation.Get().ToString());
        Console.Instance.Log("Offset Rotation: " + offsetRotation.ToString());
        Console.Instance.Log("InGame Rotation: " + temp.ToString());
    }
    void Update()
    {
        var temp1 = DeviceRotation.Get();
        var temp  = temp1.eulerAngles;
        var pos   = Input.acceleration;

        if (client.isConnected)
        {
            StringMessage msg = new StringMessage();
            msg.value = temp.x + "|" + temp.y + "|" + temp.z + "|" + pos.x + "|" + pos.y + "|" + pos.z;;
            client.Send(888, msg);
        }
    }
    private void Update()
    {
        if (inputControllers.CameraRotateMode != CameraRotateMode.Gyroscope)
        {
            return;
        }

        if (!SystemInfo.supportsGyroscope)
        {
            return;
        }

        cameraTransform.localRotation = DeviceRotation.Get();
    }
Esempio n. 11
0
    void Update()
    {
        var temp1 = DeviceRotation.Get();
        var temp  = temp1.eulerAngles;

        if (client.isConnected)
        {
            connection.interactable = false;
            status.text             = "Connected";
            StringMessage msg = new StringMessage();
            msg.value = temp.x + "|" + temp.y + "|" + temp.z;
            client.Send(888, msg);
        }
    }
Esempio n. 12
0
    void UpdateGyroInput(InputPkg ip)
    {
        Vector3 deviceEulers = DeviceRotation.Get().eulerAngles;
        Vector3 deltaEulers  = previousGyroEuler - deviceEulers;

        previousGyroEuler = deviceEulers;

        //if (deltaEulers.x > gyroXsensitivity)
        ip.gunPitch = deltaEulers.x;

        /*else
         *  ip.gunPitch = 0;*/

        //if (deltaEulers.y > gyroYsensitivity)
        ip.gunYaw = deltaEulers.y;

        /*else
         *  ip.gunYaw = 0;*/
    }
Esempio n. 13
0
    Vector3 CalculateGyroDelta()
    {
        Vector3 deviceEulers = DeviceRotation.Get().eulerAngles;
        Vector3 deltaEulers  = previousGyroEuler - deviceEulers;

        Debug.Log("Delta : " + deltaEulers);
        previousGyroEuler = deviceEulers;

        if (Mathf.Abs(deltaEulers.x) < gyroXsensitivity)
        {
            deltaEulers.x = 0;
        }

        if (Mathf.Abs(deltaEulers.y) < gyroYsensitivity)
        {
            deltaEulers.y = 0;
        }

        return(new Vector3(Mathf.Clamp(deltaEulers.x, -10f, 10f), Mathf.Clamp(deltaEulers.y, -10f, 10f)));
    }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        // ------------- Camera rotation based on gyroscope input ----------------

        // Grab the reference matrix for quaternions, as a base
        Quaternion referenceRotation = Quaternion.identity;
        // Get the current rotation of the phone
        Quaternion deviceRotation = DeviceRotation.Get();

        if (Input.gyro.enabled)
        {
            // Rotate the player's Y axis to match the camera's
            Quaternion newRot = transform.rotation;
            Vector3    euler  = newRot.eulerAngles;

            // Android SDK level is represented as an int
            // Android 6.0 Marshmallow is represented as 23
            // Since Unity can't use gyroscope.attitude in Android 6.0, check if we need
            // to use a clunky workaround on this device
            if (AndroidVer >= 23)
            {
                // We need to workaround this
                yRotation += -Input.gyro.rotationRateUnbiased.y * 2.5f;
                xRotation += -Input.gyro.rotationRateUnbiased.x * 2.5f;

                cam.transform.eulerAngles = new Vector3(xRotation, yRotation, 0f);
                //euler.y = cam.transform.eulerAngles.y;
            }
            else
            {
                // Use the nice solution
                // Rotate Camera based on gyroscope (more free)
                cam.transform.rotation = deviceRotation;
                //euler.y = deviceRotation.eulerAngles.y;
            }

            //newRot.eulerAngles = euler;
            //transform.rotation = newRot;
            // This wouldn't be so wasteful if Unity let you actually edit returned quaternions directly
        }
    }
Esempio n. 15
0
    float GetAngleByDeviceAxis(Vector3 axis)
    {
        Quaternion deviceRotation      = DeviceRotation.Get();
        Quaternion eliminationOfOthers = Quaternion.Inverse(
            Quaternion.FromToRotation(axis, deviceRotation * axis)
            );
        Vector3 filteredEuler = (eliminationOfOthers * deviceRotation).eulerAngles;

        float result = filteredEuler.z;

        if (axis == Vector3.up)
        {
            result = filteredEuler.y;
        }
        if (axis == Vector3.right)
        {
            // incorporate different euler representations.
            result = (filteredEuler.y > 90 && filteredEuler.y < 270) ? 180 - filteredEuler.x : filteredEuler.x;
        }
        return(result);
    }
Esempio n. 16
0
    void Update()
    {
        Debug.Log(songRequested.name + " + " + PlayerPrefs.GetString(songRequested.name));
        songName.text   = Truncate(songName.text, 30);
        songNameLC.text = Truncate(songNameLC.text, 34);

        //Gyro
        if (gameObject.activeSelf)
        {
            if (Input.gyro.enabled)
            {
                Quaternion deviceRotation;

                deviceRotation = DeviceRotation.Get();
                if (deviceRotation.eulerAngles.z > 45 && deviceRotation.eulerAngles.z < 225)
                {
                    landscapePanel.SetActive(true);
                }
                else
                {
                    landscapePanel.SetActive(false);
                }
            }
        }

        if (songRequested.isFavorite)
        {
            favoriteButton.GetComponent <Image>().sprite          = favoriteOn;
            favoriteButtonLandscape.GetComponent <Image>().sprite = favoriteOn;
            PlayerPrefs.SetString(songRequested.name, songRequested.isFavorite.ToString());
        }
        if (!songRequested.isFavorite)
        {
            favoriteButton.GetComponent <Image>().sprite          = favoriteOff;
            favoriteButtonLandscape.GetComponent <Image>().sprite = favoriteOff;
            PlayerPrefs.SetString(songRequested.name, songRequested.isFavorite.ToString());
        }
    }
Esempio n. 17
0
    /// <summary>
    /// Called once per frame and the end of the frame
    ///
    /// Handle all phone upate and rotation here based on
    /// the gyroscope and finger presses
    /// </summary>
    void LateUpdate( )
    {
        if (IsLocked)
        {
            return;
        }

        // Quaternion gyro = Input.gyro.attitude;
        // Vector3 accel = Input.acceleration;

        // transform.localRotation = new Quaternion ( gyro.x, gyro.y, -gyro.z, -gyro.w );

        if (Target)
        {
            Quaternion referenceRotation = Quaternion.identity;
            Quaternion deviceRotation    = DeviceRotation.Get( );

            Quaternion pitchQuat = Quaternion.Inverse(
                Quaternion.FromToRotation(referenceRotation * Vector3.right,
                                          deviceRotation * Vector3.right)
                );
            Quaternion yawQuat = Quaternion.Inverse(
                Quaternion.FromToRotation(referenceRotation * Vector3.up,
                                          deviceRotation * Vector3.up)
                );
            Vector3 pitchVect = (pitchQuat * deviceRotation).eulerAngles;
            Vector3 yawVect   = (yawQuat * deviceRotation).eulerAngles;

            Y = pitchVect.x;
            // X = yawVect.y;

            Y = ClampAngle(Y, YMinLimit, YMaxLimit);


            if (Input.touchCount == 1)
            {
                Touch touch     = Input.GetTouch(0);
                float xTouchPos = touch.position.x;

                if (Screen.width / 2 < xTouchPos)
                {
                    // Touching left
                    X += XSpeed * Time.deltaTime;
                }
                else
                {
                    // Touching right
                    X -= XSpeed * Time.deltaTime;
                }
            }
            else if (Input.touchCount == 2)
            {
                // Handle pinch

                Touch touchZero = Input.GetTouch(0);
                Touch touchOne  = Input.GetTouch(1);

                Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

                float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

                float deltaMagDiff = prevTouchDeltaMag - touchDeltaMag;

                Distance += (deltaMagDiff * ZoomSpeed * 0.02f);
            }

            if (Distance < MinDistance)
            {
                Distance = MinDistance;
            }
            else if (Distance > MaxDistance)
            {
                Distance = MaxDistance;
            }

            // Debug.Log ( X + " " + Y );
            // Debug.Log ( Distance );

            Quaternion rotation = Quaternion.Euler(Y, X, 0.0f);
            Vector3    position = rotation * new Vector3(0.0f, 0.0f, -Distance) + Target.position;

            transform.rotation = rotation;
            transform.position = position;
        }
    }
Esempio n. 18
0
    // Update is called once per frame
    void Update()
    {
        Quaternion deviceRotation = DeviceRotation.Get();

        transform.rotation = deviceRotation;
        if (Mathf.Abs(xRotation - transform.eulerAngles.x) > 1)
        {
            xRotation = Mathf.Round(transform.eulerAngles.x);
        }
        if (Mathf.Abs(yRotation - transform.eulerAngles.y) > 1)
        {
            yRotation = Mathf.Round(transform.eulerAngles.y);
        }
        if (Mathf.Abs(zRotation - transform.eulerAngles.z) > 1)
        {
            zRotation = Mathf.Round(transform.eulerAngles.z);
        }

        X.GetComponent <TextMeshProUGUI>().text          = "X = " + xRotation;
        Y.GetComponent <TextMeshProUGUI>().text          = "Y = " + yRotation;
        Z.GetComponent <TextMeshProUGUI>().text          = "Z = " + zRotation;
        errorsText.GetComponent <TextMeshProUGUI>().text = "Errores = " + errorsCont;

        if (!isStabilized)
        {
            startCalibration();

            if (xRotation > 88 && xRotation < 91)
            {
                timePassed   += Time.deltaTime;
                progressValue = timePassed / secondsToCalibrate;
                if (progressValue > 1)
                {
                    progressValue = 1;
                }
                progressCalibration.GetComponent <Image>().fillAmount = progressValue;

                if (timePassed > secondsToCalibrate)
                {
                    endCalibration();
                }
            }
            else
            {
                timePassed = 0;
                progressCalibration.GetComponent <Image>().fillAmount = 0;
            }
        }


        if (IntroductionComplete)
        {
            switch (_exercises)
            {
            case EnumExercises.ARMEXERCISE:

                if (repetitionCounter < 3)
                {
                    if (xRotation <= 45)
                    {
                        if (!repetitionCompleted)
                        {
                            _audioSource.clip = correct;
                            _audioSource.Play();
                            repetitionCompleted = true;
                            repetitionCounter++;
                        }
                    }

                    if (xRotation >= 90)
                    {
                        if (repetitionCompleted)
                        {
                            _audioSource.clip = correct;
                            _audioSource.Play();
                            repetitionCompleted = false;
                        }
                    }
                }
                else
                {
                    _audioSource.clip = exerciseComplete;
                    _audioSource.Play();
                    //feedback
                }
                break;

            case EnumExercises.SHOULDEREXERCISE:

                if (setCounter < set)
                {
                    if (repetitionCounter < repetitions)
                    {
                        if (xRotation > 15 && xRotation < 300)
                        {
                            wrongXPosition = true;
                        }
                        else
                        {
                            wrongXPosition = false;
                        }

                        if (yRotation > safeZoneA || yRotation < safeZoneB)
                        {
                            wrongYPosition = true;
                        }
                        else
                        {
                            wrongYPosition = false;
                        }


                        if (zRotation >= 177 && zRotation <= 181)
                        {
                            firstStateCompleted();
                        }

                        if (zRotation >= 88 && zRotation <= 91)
                        {
                            secondStateCompleted();
                        }

                        if ((zRotation >= 0 && zRotation <= 2) || (zRotation >= 357 && zRotation <= 360))
                        {
                            thirdStateCompleted();
                        }

                        wrongDirectionError();
                    }
                    else
                    {
                        nextSet();
                    }
                }
                else
                {
                    endOfActivity();
                }

                break;
            }
        }
    }
Esempio n. 19
0
 void Update()
 {
     console.text = "La aceleracion es :" + Input.acceleration.magnitude + " y la rotacion en x es :" + DeviceRotation.Get().eulerAngles.x;
     if (Input.acceleration.magnitude > maxAceleration)
     {
         maxAceleration = Input.acceleration.magnitude;
         maxAccelerationConsole.text = "Aceleracion maxima = " + maxAceleration;
     }
 }
Esempio n. 20
0
    void Update()
    {
        Quaternion deviceRotation = DeviceRotation.Get();

        transform.rotation = deviceRotation;
    }
Esempio n. 21
0
    // Update is called once per frame
    void Update()
    {
        //dont want player doing things while updating networking
        lock (ACTION_LOCK)
        {
            // Add time since last frame to LastShotTime to advance the cooldown
            LastShotTime += Time.deltaTime;

            // Get player's CharacterController so we can move them around
            CharacterController player = GetComponent <CharacterController>();

            // Get touch joystick input as horizontal and vertical components
            float hor  = CrossPlatformInputManager.GetAxis("Horizontal");
            float vert = CrossPlatformInputManager.GetAxis("Vertical");

            // Set running state based on input
            animator.SetFloat("Moving", Mathf.Abs(vert));

            // Move player based on input and speed
            player.SimpleMove(transform.forward * vert * MoveSpeed);
            player.SimpleMove(transform.right * hor * MoveSpeed);

            //Move camera with player
            cam.transform.position = transform.position + offset;

            // ------------- Camera rotation based on gyroscope input ----------------

            // Grab the reference matrix for quaternions, as a base
            Quaternion referenceRotation = Quaternion.identity;
            // Get the current rotation of the phone
            Quaternion deviceRotation = DeviceRotation.Get();

            //never mind (keep for now just in case)
            //offset device rotation's y axis by -90 degrees because it defaults to a 90 degree rotation for some reason
            //deviceRotation.eulerAngles.Set(deviceRotation.eulerAngles.x, deviceRotation.eulerAngles.y - 90, deviceRotation.eulerAngles.z);

            if (Input.gyro.enabled)
            {
                yRotation += -Input.gyro.rotationRateUnbiased.y * 2.5f;
                xRotation += -Input.gyro.rotationRateUnbiased.x * 2.5f;

                cam.transform.eulerAngles = new Vector3(xRotation, yRotation, 0f);

                // Rotate Camera based on gyroscope (more free)
                //cam.transform.rotation = deviceRotation;

                // Rotate the player's Y axis to match the camera's
                Quaternion newRot = transform.rotation;
                Vector3    euler  = newRot.eulerAngles;
                //euler.y = deviceRotation.eulerAngles.y;
                euler.y            = cam.transform.eulerAngles.y;
                newRot.eulerAngles = euler;
                transform.rotation = newRot;
                // This wouldn't be so wasteful if Unity let you actually edit returned quaternions directly
            }
            //don't want both
            else
            {
                // ------------- Alternate camera controls: swipe to rotate --------------

                float rotX = CrossPlatformInputManager.GetAxis("CamHorizontal");

                // Only rotate on Y axis (Prevents camera clip issues)
                //cam.transform.Rotate(new Vector3(0f, -rotX * RotSpeed * Time.deltaTime, 0f));
                transform.Rotate(new Vector3(0f, -rotX * RotSpeed * Time.deltaTime, 0f));
            }
            // ------------- Firing shots ----------------

            // Check if player pressed Fire, and cooldown has expired
            if (CrossPlatformInputManager.GetButtonDown("Fire") && LastShotTime >= Cooldown)
            {
                sf   = true;
                sfx  = cam.transform.position.x;
                sfz  = cam.transform.position.z;
                sfrx = cam.transform.forward.x; //cam.transform.rotation.eulerAngles.x;
                sfry = cam.transform.forward.y; //cam.transform.rotation.eulerAngles.y;
                sfrz = cam.transform.forward.z; //cam.transform.rotation.eulerAngles.z;

                // Fire a shot by instantiating a bullet and calculating with a raycast
                // First get orientation of camera and adjust laser's start position so it's outside the player's collider
                Vector3    shotPos = transform.TransformDirection(1f, -0.5f, 1f) + cam.transform.position;
                Quaternion shotRot = cam.transform.rotation;
                FireSFX.Play();

                // Make a raycast from the camera to check for target hit
                RaycastHit hit; // Var to store info on what got hit
                                // Location in world space of the ray's endpoint
                Vector3 endPoint = Vector3.zero;

                //Debug.DrawRay(cam.transform.position, cam.transform.forward*200f, Color.red, 20f, true);

                // Test if the raycast hits anything
                if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, 200f))
                {
                    // Retrieve endpoint
                    endPoint = hit.point;

                    // Check what we hit and act accordingly
                    switch (hit.collider.tag)
                    {
                    case "Enemy":
                        // Get that player's stats and take off some HP
                        e_defense = hit.collider.gameObject.GetComponent <EnemyStatus>().getDefense();
                        float damage = Math.Max(attack - e_defense, 1);
                        //if (damage < 0)
                        //    damage = 0f;
                        hit.collider.gameObject.GetComponent <EnemyStatus>().TakeHP(damage);
                        ehit = true;
                        Debug.Log("Hit enemy");
                        // Spawn some sparks to let you know you hit them
                        GameObject sparks = Instantiate(SparkSys, hit.point, Quaternion.identity);
                        // And play sfx
                        enemyHitSFX.Play();
                        break;

                    default:
                        // Other cases to consider: wall, arena border, ground
                        // Spawn a cloud of dust
                        GameObject dust = Instantiate(DustSys, hit.point, Quaternion.identity);
                        // play hit other sfx
                        otherHitSFX.Play();
                        break;
                    }
                }

                // Change origin of shot to make it look like it's coming from the gun
                //shotPos = transform.TransformDirection(1f, -0.5f, 1f) + cam.transform.position;

                // Instantiate shot where camera is
                makeShot(shotPos, shotRot, endPoint);

                // Reset time since last shot to enforce cooldown
                LastShotTime = 0f;

                // Animate the player
                animator.SetTrigger("FireT");
            }
        }
    }