예제 #1
0
        private void InitDrone()
        {
#if MULTIPLEDRONES
            #region Multiple Drones
            // Get IP of devices if you have multiples drone on the network
            ListOfDevices = new List <MiniDevice>();
            for (int i = 1; i < 8; i++)
            {
                Button btn = new Button()
                {
                    Content = ""
                };
                btn.Visibility = Visibility.Hidden;
                btn.Click     += Btn_Click;
                stckPanel.Children.Add(btn);
                string hostname = prefixName + i.ToString() + DNSString;
                ListOfDevices.Add(new MiniDevice()
                {
                    Name = hostname, Button = btn, Id = i
                });
            }

            List <string> listOfName = new List <string>();
            foreach (MiniDevice str in ListOfDevices)
            {
                listOfName.Add(str.Name);
            }
            #endregion

            // Create Controller
            controller = new SumoController(out piloting, listOfName, true);
#else
            controller = new SumoController(out piloting);
#endif
            controller.ImageAvailable += Controller_ImageAvailable;
            controller.SumoEvents     += Controller_SumoEvents;

            // Connect Piloting Events to control Sumo
            piloting.Disconnect            += Piloting_Disconnect;
            piloting.Move                  += Piloting_Move;
            piloting.KeyboardKeysAvailable += Piloting_KeyboardKeysAvailable;

            // If you want process video in OpenCV separate window Set EnableOpenCV to true
            // In this case controller.ImageAvailable is not fired
            //controller.EnableOpenCV = true;
        }
예제 #2
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "AISumo" && gameObject.tag == "Player")
        {
            if (!StartKnockBack)
            {
                Rigidbody      RBOther   = collision.gameObject.GetComponent <Rigidbody>();
                SumoController SCOther   = collision.gameObject.GetComponent <SumoController>();
                NavMeshAgent   NA        = collision.gameObject.GetComponent <NavMeshAgent>();
                Vector3        Direction = (collision.gameObject.transform.position - transform.position).normalized;
                float          SpeedInDirectionPersonal = Mathf.Abs(RB.velocity.magnitude);
                float          SpeedInDirectionOther    = Mathf.Abs(NA.velocity.magnitude);

                //Debug.Log("Speeds: " + gameObject.name + " " + SpeedInDirectionPersonal + " " + collision.gameObject.name + " " + SpeedInDirectionOther);
                //float Force = 0;
                if (SpeedInDirectionPersonal > SpeedInDirectionOther)
                {
                    RB.velocity = Vector3.zero;
                    RB.AddForce(-Direction * CollisionForce * WinKnockbackPercent / 100, ForceMode.Impulse);
                    //Force = ChargeForce * WinKnockbackPercent / 100;
                    RBOther.AddForce(Direction * CollisionForce * (LossKnockBackPercent + 20) / 100, ForceMode.Impulse); // 20 is the fudge factor
                    //Debug.Log(gameObject.name + " Was Hit with (Win)");
                    SCOther.LostCollision = true;
                }
                else if (SpeedInDirectionPersonal < SpeedInDirectionOther)
                {
                    RB.velocity = Vector3.zero;
                    RB.AddForce(-Direction * CollisionForce * LossKnockBackPercent / 100, ForceMode.Impulse);
                    //Force = ChargeForce * LossKnockBackPercent / 100;
                    RBOther.AddForce(Direction * CollisionForce * WinKnockbackPercent / 100, ForceMode.Impulse);
                    //Debug.Log(gameObject.name + " Was Hit with (Loss)");
                }
                else
                {
                    RB.velocity = Vector3.zero;
                    RB.AddForce(-Direction * CollisionForce * TieKnockBackPercent / 100, ForceMode.Impulse);
                    RBOther.AddForce(Direction * CollisionForce * TieKnockBackPercent / 100, ForceMode.Impulse);
                    //Force = ChargeForce * TieKnockBackPercent / 100;
                    //Debug.Log(gameObject.name + " Was Hit with (Tie)");
                }
            }
        }
        else if (collision.gameObject.tag == "AISumo" && gameObject.tag == "AISumo")
        {
            if (!StartKnockBack)
            {
                Rigidbody    RBOther    = collision.gameObject.GetComponent <Rigidbody>();
                NavMeshAgent NA         = collision.gameObject.GetComponent <NavMeshAgent>();
                NavMeshAgent NAPersonal = gameObject.GetComponent <NavMeshAgent>();
                Vector3      Direction  = (collision.gameObject.transform.position - transform.position).normalized;
                float        SpeedInDirectionPersonal = Mathf.Abs(NAPersonal.velocity.magnitude);
                float        SpeedInDirectionOther    = Mathf.Abs(NA.velocity.magnitude);

                //Debug.Log("Speeds: " + gameObject.name + " " + SpeedInDirectionPersonal + " " + collision.gameObject.name + " " + SpeedInDirectionOther);
                //float Force = 0;
                if (SpeedInDirectionPersonal > SpeedInDirectionOther)
                {
                    RB.velocity = Vector3.zero;
                    RB.AddForce(-Direction * CollisionForce * WinKnockbackPercent / 100, ForceMode.Impulse);
                    //Force = ChargeForce * WinKnockbackPercent / 100;
                    //Debug.Log(gameObject.name + " Was Hit with (Win)");
                }
                else if (SpeedInDirectionPersonal < SpeedInDirectionOther)
                {
                    RB.velocity = Vector3.zero;
                    RB.AddForce(-Direction * CollisionForce * LossKnockBackPercent / 100, ForceMode.Impulse);
                    //Force = ChargeForce * LossKnockBackPercent / 100;
                    //Debug.Log(gameObject.name + " Was Hit with (Loss)");
                }
                else
                {
                    RB.velocity = Vector3.zero;
                    RB.AddForce(-Direction * CollisionForce * TieKnockBackPercent / 100, ForceMode.Impulse);
                    //Force = ChargeForce * TieKnockBackPercent / 100;
                    //Debug.Log(gameObject.name + " Was Hit with (Tie)");
                }
            }
        }
        if (gameObject.tag == "AISumo" && collision.gameObject.tag == "Player")
        {
            //if (!StartKnockBack)
            //{
            //    Rigidbody RBOther = collision.gameObject.GetComponent<Rigidbody>();
            //    NavMeshAgent NA = gameObject.GetComponent<NavMeshAgent>();
            //    Vector3 Direction = (collision.gameObject.transform.position - transform.position).normalized;
            //    float SpeedInDirectionPersonal = Mathf.Abs(NA.velocity.magnitude);
            //    float SpeedInDirectionOther = Mathf.Abs(RBOther.velocity.magnitude);

            //    //Debug.Log("Speeds: " + gameObject.name + " " + SpeedInDirectionPersonal + " " + collision.gameObject.name + " " + SpeedInDirectionOther);
            //    float Force = 0;
            //    if (SpeedInDirectionPersonal > SpeedInDirectionOther)
            //    {
            //        RB.velocity = Vector3.zero;
            //        RB.AddForce(-Direction * ChargeForce * WinKnockbackPercent / 100, ForceMode.Impulse);
            //        Force = ChargeForce * WinKnockbackPercent / 100;
            //        Debug.Log(gameObject.name + " Was Hit with (Win)");
            //    }
            //    else if (SpeedInDirectionPersonal < SpeedInDirectionOther)
            //    {
            //        RB.velocity = Vector3.zero;
            //        RB.AddForce(-Direction * ChargeForce * LossKnockBackPercent / 100, ForceMode.Impulse);
            //        Force = ChargeForce * LossKnockBackPercent / 100;
            //        Debug.Log(gameObject.name + " Was Hit with (Loss)");
            //    }
            //    else
            //    {
            //        RB.velocity = Vector3.zero;
            //        RB.AddForce(-Direction * ChargeForce * TieKnockBackPercent / 100, ForceMode.Impulse);
            //        Force = ChargeForce * TieKnockBackPercent / 100;
            //        Debug.Log(gameObject.name + " Was Hit with (Tie)");
            //    }
            //}
        }
    }