Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //Vector3
        Vector3 mouse = Input.mousePosition;

        mouse.z = 10;
        mouseCube.transform.position = cam.ScreenToWorldPoint(mouse);

        filterdCube.transform.position = cam.ScreenToWorldPoint(kalman.Update(mouse));
    }
Esempio n. 2
0
    void Update()
    {
        /* MOUSE NAV IN EDITOR */

#if UNITY_EDITOR
        if (Input.GetMouseButtonUp(0) && Time.time - DoubleClickTime >= 0.2f)
        {
            DoubleClickTime = Time.time;
        }
        else if (Input.GetMouseButtonUp(0) && Time.time - DoubleClickTime < 0.2f)
        {
            destinationPoint   = this.GetComponent <Camera>().ScreenToWorldPoint(Input.mousePosition);
            destinationPoint.z = userZIndex;

            if (Vector2.Distance(this.transform.position, destinationPoint) > 90)
            {
                this.transform.position = destinationPoint;
                pd.ClearPath();
            }
            else
            {
                pathPoints.Add(this.transform.position);
                pd.RedrawPath();
            }

            /*--------------------------------------------------------------CLOUD!!!!*/
            cs.TraveledDistance += (int)(Vector2.Distance(this.transform.position, destinationPoint) / 2.7f);
            PlayerPrefs.SetInt("TraveledDistance", cs.TraveledDistance);
            /*--------------------------------------------------------------CLOUD!!!!*/

            Vector3 rot = destinationPoint - this.transform.position;
            destinationAngle    = (rot.x < 0 ? Vector3.Angle(rot, Vector3.up) : 360 - Vector3.Angle(rot, Vector3.up));
            location.unitySpeed = 40;
            float angleDiff = Mathf.Abs(Mathf.DeltaAngle(this.transform.localEulerAngles.z, destinationAngle));
            rotationSpeed = (angleDiff / 360) * 400;
        }
#else
        /* MOVEMENT WITH GPS */
        if (location.readPosition())
        {
            /* IF USER MOVED */
            destinationPoint   = location.currentPos;
            destinationPoint.z = userZIndex;

            /* Kalman filtering */
            if (Time.time - kalmanTimer > kalmanTurnOnTiemout)
            {
                destinationPoint = kalman.Update(destinationPoint);
            }
            else
            {
                kalman.Update(destinationPoint);
            }

            /*--------------------------------------------------------------CLOUD!!!!*/
            cs.TraveledDistance += (int)(Vector2.Distance(this.transform.position, destinationPoint) / 2.75f);
            PlayerPrefs.SetInt("TraveledDistance", cs.TraveledDistance);
            /*--------------------------------------------------------------CLOUD!!!!*/

            if (firstGPSRead)
            {
                firstGPSRead            = false;
                this.transform.position = destinationPoint;
            }
            else
            {
                Vector3 rot = destinationPoint - this.transform.position;
                destinationAngle = (rot.x < 0 ? Vector3.Angle(rot, Vector3.up) : 360 - Vector3.Angle(rot, Vector3.up));
                rotationSpeed    = (Mathf.Abs(Mathf.DeltaAngle(this.transform.localEulerAngles.z, destinationAngle)) / 360) * 144;
            }

            if (Vector2.Distance(this.transform.position, destinationPoint) > 90)
            {
                this.transform.position = destinationPoint;
                pd.ClearPath();
            }
            else
            {
                pathPoints.Add(this.transform.position);
                pd.RedrawPath();
            }
        }
#endif

        this.transform.position = Vector3.MoveTowards(this.transform.position, destinationPoint, (float)(location.unitySpeed) * 1.44f * Time.deltaTime);

        this.transform.localEulerAngles = new Vector3(0, 0, Mathf.MoveTowardsAngle(this.transform.localEulerAngles.z, destinationAngle, Time.deltaTime * rotationSpeed));

        if (Vector2.Distance(destinationPoint, latestGooglePoisDownloadPosition) > 125)
        {
            DownloadGooglePOIs(destinationPoint);
        }
    }
Esempio n. 3
0
 public void record(Vector3 input)
 {
     recording = kalman.Update(input);
 }