Example #1
0
 private void CheckJoystick()
 {
     if (joystick.Instance != null)
     {
         joystick stick     = joystick.Instance;
         int      failCount = 0;
         if (stick.TL < 20.0f && stick.TL > -20.0f)
         {
             failCount++;
         }
         if (stick.TR < 20.0f && stick.TR > -20.0f)
         {
             failCount++;
         }
         if (stick.BL < 20.0f && stick.BL > -20.0f)
         {
             failCount++;
         }
         if (stick.BR < 20.0f && stick.BR > -20.0f)
         {
             failCount++;
         }
         if (failCount > 2)
         {
             return;
         }
         //Debug.Log("Leading Foot: " + LeadingFoot);
         switch (LeadingFoot)
         {
         case LeadingFootEnum.Right:
         case LeadingFootEnum.Left:
         case LeadingFootEnum.Neutral:
         {
             if ((stick.TL > stick.BL) && (stick.TR < stick.BR))         // valid turning form
             {
                 RotateRight();
                 //Debug.Log("Rotate Right");
             }
             else if ((stick.BL > stick.TL) && (stick.BR < stick.TR))        // valid turning form
             {
                 RotateLeft();
                 //Debug.Log("Rotate Left");
             }
             else                                                    // this means we're on an edge, find out which edge and either slow down or flip
             {
                 if ((stick.BL > stick.TL) && (stick.BR > stick.TR)) // heel edge
                 {
                     SlowDown();
                 }
                 else if ((stick.TL > stick.BL) && (stick.TR > stick.BR))        // toe edge
                 {
                     SlowDown();
                 }
             }
         }
         break;
         }
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        joystick stick = GetComponent <joystick>();

        if (stick.GetHorizontalValue() != 0.0f ||
            stick.GetVerticalValue() != 0.0f)
        {
            GetComponent <AudioSource>().Play();
        }
        else
        {
            GetComponent <AudioSource>().Stop();
        }
    }
Example #3
0
 /// <summary>
 /// Check which hand is grabbing the object by checking trigger pressing
 /// Note: May need to be changed if grabbing with other buttons
 /// </summary>
 private void GetHandGrabbing()
 {
     if (ViveInput.GetPressEx(HandRole.LeftHand, ControllerButton.Trigger))
     {
         handGrabbing = joystick.leftHand;
     }
     else if (ViveInput.GetPressEx(HandRole.RightHand, ControllerButton.Trigger))
     {
         handGrabbing = joystick.rightHand;
     }
     else
     {
         handGrabbing = joystick.none;
     }
 }
Example #4
0
        private void backgroundWorker_joystick_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                Thread.Sleep(10);
                try
                {
                    Gamepad_State_SlimDX joy = new Gamepad_State_SlimDX(SlimDX.XInput.UserIndex.One);
                    joy.Update();

                    joystick js = new joystick();
                    js.pitch    = (Int16)(joy.LeftStick.Position.Y * 250);
                    js.roll     = (Int16)(joy.LeftStick.Position.X * 250);
                    js.throttle = (Int16)(joy.RightStick.Position.Y * 10);
                    js.yaw      = (Int16)(joy.RightStick.Position.X * 250);

                    if (joy.B)
                    {
                        js.emergency = 1;
                    }
                    else
                    {
                        js.emergency = 0;
                    }

                    if (joy.A)
                    {
                        js.takeoff = 1;
                    }
                    else
                    {
                        js.takeoff = 0;
                    }

                    string json = JsonConvert.SerializeObject(js);

                    udp_send_recv(3000, json, 5);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        joystick stick = GetComponent <joystick>();

        if ((stick.GetHorizontalValue() != 0.0f ||
             stick.GetVerticalValue() != 0.0f) &&
            delay >= bulletdelay)
        {
            Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            GameObject newPrefab = Instantiate(SomPrefab);
            newPrefab.transform.position             = startpoint.transform.position;
            newPrefab.GetComponent <bullet>().player = player;

            Vector2 direction = new Vector2(stick.GetHorizontalValue(), stick.GetVerticalValue());
            direction.Normalize();
            newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed);
            delay = 0.0f;
        }
    }
Example #6
0
 void OnDestroy()
 {
     Instance = null;
 }
Example #7
0
 void Awake()
 {
     Instance = this;
 }
Example #8
0
 void OnDestroy()
 {
     Instance = null;
 }
Example #9
0
 void Awake()
 {
     Instance = this;
 }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        joystick stick = GetComponent <joystick>();

        if ((stick.GetHorizontalValue() != 0.0f ||
             stick.GetVerticalValue() != 0.0f) &&
            delay >= bulletdelay)
        {
            if (PlayerPrefs.GetString("equip") == "gun-r2")
            {
                Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                GameObject newPrefab = Instantiate(SomPrefab);
                newPrefab.transform.position             = startpoint.transform.position;
                newPrefab.GetComponent <bullet>().player = player;

                Vector2 direction = new Vector2(stick.GetHorizontalValue(), stick.GetVerticalValue());
                direction.Normalize();
                newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed * 1.05f);
                delay = bulletdelay * 0.05f;
            }
            else if (PlayerPrefs.GetString("equip") == "gun-b1")
            {
                Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                GameObject newPrefab = Instantiate(SomPrefab);
                newPrefab.transform.position             = startpoint.transform.position;
                newPrefab.GetComponent <bullet>().player = player;

                Vector2 direction = new Vector2(stick.GetHorizontalValue(), stick.GetVerticalValue());
                direction.Normalize();
                newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed * 1.06f);
                delay = bulletdelay * 0.1f;
            }
            else if (PlayerPrefs.GetString("equip") == "gun-g1")
            {
                Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                GameObject newPrefab = Instantiate(SomPrefab);
                newPrefab.transform.position             = startpoint.transform.position;
                newPrefab.GetComponent <bullet>().player = player;

                Vector2 direction = new Vector2(stick.GetHorizontalValue(), stick.GetVerticalValue());
                direction.Normalize();
                newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed * 1.1f);
                delay = bulletdelay * 0.1f;
            }
            else if (PlayerPrefs.GetString("equip") == "gun-y3")
            {
                Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                GameObject newPrefab = Instantiate(SomPrefab);
                newPrefab.transform.position             = startpoint.transform.position;
                newPrefab.GetComponent <bullet>().player = player;

                Vector2 direction = new Vector2(stick.GetHorizontalValue(), stick.GetVerticalValue());
                direction.Normalize();
                newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed * 1.15f);
                delay = bulletdelay * 0.1f;
            }
            else if (PlayerPrefs.GetString("equip") == "gun-g3")
            {
                Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                GameObject newPrefab = Instantiate(SomPrefab);
                newPrefab.transform.position             = startpoint.transform.position;
                newPrefab.GetComponent <bullet>().player = player;

                Vector2 direction = new Vector2(stick.GetHorizontalValue(), stick.GetVerticalValue());
                direction.Normalize();
                newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed * 1.16f);
                delay = bulletdelay * 0.11f;
            }
            else
            {
                Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                GameObject newPrefab = Instantiate(SomPrefab);
                newPrefab.transform.position             = startpoint.transform.position;
                newPrefab.GetComponent <bullet>().player = player;

                Vector2 direction = new Vector2(stick.GetHorizontalValue(), stick.GetVerticalValue());
                direction.Normalize();
                newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed);
                delay = 0.0f;
            }
        }
        delay += Time.deltaTime;
        if (Input.GetKey(KeyCode.Q) && Qnowofftime <= 0)
        {
            Qnowofftime = Qcooltime;

            Vector3 gameWorldpos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            GameObject newPrefab = Instantiate(QPrefab);
            newPrefab.transform.position            = transform.position;
            newPrefab.GetComponent <skill>().player = gameObject;

            Vector2 direction = gameWorldpos - transform.position;
            direction.Normalize();
            newPrefab.GetComponent <Rigidbody2D>().AddForce(direction * BulletSpeed);
        }

        if (Qnowofftime > 0.0)
        {
            Qnowofftime -= Time.deltaTime;
        }
    }