예제 #1
0
    public void updateMass()
    {
        if (masse.text != "")
        {
            DataProjectile dp = _projectile.First().GetComponent <DataProjectile> ();

            float m;
            bool  isNumeric = float.TryParse(masse.text, out m);
            if (!isNumeric || m <= 0)
            {
                dp.masse   = 1f;
                masse.text = "1";
            }
            else if (m > 999)
            {
                dp.masse   = 999f;
                masse.text = "999";
            }
            else
            {
                dp.masse = Convert.ToSingle(masse.text);
            }
            shoot.interactable = true;
        }
    }
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _projectile)
        {
            Move           mo = go.GetComponent <Move> ();
            DataProjectile dp = go.GetComponent <DataProjectile> ();
            Rigidbody2D    rb = go.GetComponent <Rigidbody2D> ();

            float dt = Time.deltaTime;

            if (mo.inMovement == true)
            {
                //si le projectile sort du champ de la caméra, le remettre à la position initiale
                if (go.transform.position.x > 3f * Camera.main.orthographicSize || go.transform.position.x < -3f * Camera.main.orthographicSize ||
                    go.transform.position.y > 4f * Camera.main.orthographicSize)
                {
                    mo.inMovement     = false;
                    mo.new_projectile = true;
                }

                //surface du projectile
                float S = Mathf.PI * Mathf.Pow(dp.rayon, 2);
                //volume du projectile
                float V = (4f / 3f) * Mathf.PI * Mathf.Pow(dp.rayon, 3);

                //equations du cours
                float delta_x = (mo.vitesse.x * dt) - ((Cx * S * mvAir * Mathf.Pow(mo.vitesse.x, 2) * Mathf.Pow(dt, 2)) / (dp.masse * 4f));
                float delta_y = 0f;
                mo.vitesse.x -= (Cx * S * mvAir * Mathf.Pow(mo.vitesse.x, 2) * dt) / (2f * dp.masse);
//				mo.vitesse.x = (mo.vitesse.x <= 0) ? 0 : mo.vitesse.x ;

                //si le projectile n'a pas touché le sol, modification de y(t) et Vy(t)
                if (mo.groundContact == false)
                {
                    delta_y                  = (mo.vitesse.y * dt) + (mo.earth_gravity.y / 2f) * Mathf.Pow(dt, 2) - ((Cx * S * mvAir * Mathf.Pow(mo.vitesse.y, 2) * Mathf.Pow(dt, 2)) / (4f * dp.masse)) - ((mvAir * V * mo.earth_gravity.y) / 2f * dp.masse * Mathf.Pow(dt, 2));
                    mo.vitesse.y            += mo.earth_gravity.y * dt - ((Cx * S * mvAir * Mathf.Pow(mo.vitesse.y, 2) * dt) / (2f * dp.masse)) - (mvAir * V * mo.earth_gravity.y * dt / dp.masse);
                    go.transform.eulerAngles = new Vector3(0, 0, mo.vitesse.y * Mathf.Rad2Deg);
                }
                else
                {
                    //le projectile a touché le sol -> force de frottement + plus de modification sur l'axe des y
                    delta_x                 += mu * (mo.earth_gravity.y / 2f) * Mathf.Pow(dt, 2);
                    mo.vitesse.x            += mu * mo.earth_gravity.y * dt;
                    go.transform.eulerAngles = new Vector3(0, 0, mo.vitesse.x * Mathf.Rad2Deg);
                    // si la vitesse est nulle, le projectile ne bouge plus, on le remet à la position initiale après une courte pause
                    if (mo.vitesse.x <= 0f && mo.vitesse.y <= 0f)
                    {
                        mo.inMovement = false;
                        //faire une pause pour l'affichage
                        go.AddComponent <WaitAir>();
                    }
                }

                go.transform.position += new Vector3(delta_x, delta_y, 0f);
            }
        }
    }
예제 #3
0
    // private bool end = false;

    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _projectile)
        {
            Move           mo = go.GetComponent <Move> ();
            DataProjectile dp = go.GetComponent <DataProjectile> ();
            Rigidbody2D    rb = go.GetComponent <Rigidbody2D> ();

            float dt = Time.deltaTime;

            if (mo.inMovement == true)
            {
//				go.transform.position += mo.vitesse * dt + ((mo.earth_gravity / dp.masse) * Mathf.Pow (dt, 2)) / 2f;
//
//				mo.vitesse += 0.5f * (2 * mo.earth_gravity / dp.masse) * dt;

                //si le projectile sort du champ de la caméra
                if (go.transform.position.x > 3f * Camera.main.orthographicSize || go.transform.position.x < -3f * Camera.main.orthographicSize)
                {
                    mo.inMovement     = false;
                    mo.new_projectile = true;
                }

                //equations du cours
                float delta_x = (mo.vitesse.x * dt);
                float delta_y = 0f;
                // coeff frottement solide
                float mu = 0.5f;

                //si le projectile n'a pas touché le sol
                if (mo.groundContact == false)
                {
                    delta_y                  = (mo.vitesse.y * dt) + (mo.earth_gravity.y / 2f) * Mathf.Pow(dt, 2);
                    mo.vitesse.y            += mo.earth_gravity.y * dt;
                    go.transform.eulerAngles = new Vector3(0, 0, mo.vitesse.y * Mathf.Rad2Deg);
                }
                else
                {
//					if (end == false ) {
//						float dist = mo.vitesse_init.x*mo.vitesse_init.y/9.81f;
//						float hauteur = 0.5f * Mathf.Pow (mo.vitesse_init.y, 2)/9.81f;
//						end = true;
//						Debug.Log ("hauteur: "+hauteur);
//						Debug.Log("dist calcule: "+dist);
//
//						GameObject g = GameObject.FindGameObjectWithTag ("cross");
//						GameObject newc = Object.Instantiate<GameObject> (g);
//						GameObjectManager.bind (newc);
//						newc.transform.position = go.transform.position;
//
//					}

                    //le projectile a touché le sol -> force de frottement
                    delta_x                 += mu * (mo.earth_gravity.y / 2f) * Mathf.Pow(dt, 2);
                    mo.vitesse.x            += mu * mo.earth_gravity.y * dt;
                    go.transform.eulerAngles = new Vector3(0, 0, mo.vitesse.x * Mathf.Rad2Deg);
                    // si la vitesse est nulle, le projectile ne bouge plus
                    if (mo.vitesse.x <= 0f && mo.vitesse.y <= 0f)
                    {
                        mo.inMovement = false;
                        //faire une pause pour l'affichage
                        go.AddComponent <Wait>();
                    }
                }

                go.transform.position += new Vector3(delta_x, delta_y, 0f);
            }

//			Vector2 movement = new Vector2 (Mathf.Cos (mo.angle*Mathf.PI/180), Mathf.Sin (mo.angle*Mathf.PI/180));
//			dp.set_calculated_velocity(movement * mo.vitesse);

            // angle = cos-1(x)
        }
    }
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _projectile)
        {
            Move           mo = go.GetComponent <Move> ();
            DataProjectile dp = go.GetComponent <DataProjectile> ();
            Rigidbody2D    rb = go.GetComponent <Rigidbody2D> ();

//			float dt = Time.deltaTime;
            float dt = 0.01f;

            if (mo.inMovement == true)
            {
                //si le projectile sort du champ de la caméra
                if (go.transform.position.x > 3f * Camera.main.orthographicSize || go.transform.position.x < -3f * Camera.main.orthographicSize ||
                    go.transform.position.y > 4f * Camera.main.orthographicSize || go.transform.position.y < -3f * Camera.main.orthographicSize)
                {
                    mo.inMovement     = false;
                    mo.new_projectile = true;
                }

                //sigma pour Stokes
                float sigma = 6 * Mathf.PI * dp.rayon;

                //surface du projectile
                float S = Mathf.PI * Mathf.Pow(dp.rayon, 2);
                //volume du projectile
                float V = (4f / 3f) * Mathf.PI * Mathf.Pow(dp.rayon, 3);

                //equations du cours
                float delta_x = (mo.vitesse.x * dt) - ((Cx * S * mvEau * Mathf.Pow(mo.vitesse.x, 2) * Mathf.Pow(dt, 2)) / (dp.masse * 4f));
                Debug.Log("delta x");
                Debug.Log(delta_x);
                Debug.Log("force");
                Debug.Log(-(Cx * S * mvEau * Mathf.Pow(mo.vitesse.x, 2) * Mathf.Pow(dt, 2)) / (dp.masse * 4f));
                float delta_y = 0f;
                mo.vitesse.x -= (Cx * S * mvEau * Mathf.Pow(mo.vitesse.x, 2) * dt) / (2f * dp.masse);
                Debug.Log("vitesse x");
                Debug.Log(mo.vitesse.x);
                Debug.Log("force");
                Debug.Log(-(Cx * S * mvEau * Mathf.Pow(mo.vitesse.x, 2) * dt) / (2f * dp.masse));
                if (mo.vitesse.x <= 0f)
                {
                    mo.vitesse.x = 0f;
                }

                //si le projectile n'a pas touché le sol
                if (mo.groundContact == false)
                {
                    delta_y = (mo.vitesse.y * dt) + (mo.earth_gravity.y / 2f) * Mathf.Pow(dt, 2) - ((Cx * S * mvEau * Mathf.Pow(mo.vitesse.y, 2) * Mathf.Pow(dt, 2)) / (4f * dp.masse)) - ((mvEau * V * mo.earth_gravity.y) * Mathf.Pow(0.01f, 2) / 2f * dp.masse);
//					Debug.Log ("v*t");
//					Debug.Log (mo.vitesse.y * dt);
//					Debug.Log ("gravity");
//					Debug.Log((mo.earth_gravity.y / 2f) * Mathf.Pow (dt, 2));
//					Debug.Log ("force");
//					Debug.Log(- ((Cx * S * mvEau * Mathf.Pow (mo.vitesse.y, 2) * Mathf.Pow(dt,2))/(4f*dp.masse)));
//					Debug.Log ("archimede");
//					Debug.Log(-((mvEau*V*mo.earth_gravity.y)* Mathf.Pow(0.01f,2)/2f*dp.masse ));
//					Debug.Log ("v*t - gravity - force + pA");
//					Debug.Log (mo.vitesse.y * dt + (mo.earth_gravity.y / 2f) * Mathf.Pow (dt, 2) - ((Cx * S * mvEau * Mathf.Pow (mo.vitesse.y, 2) * Mathf.Pow(dt,2))/(4f*dp.masse))-((mvEau*V*mo.earth_gravity.y)* Mathf.Pow(0.01f,2)/2f*dp.masse));

                    mo.vitesse.y += mo.earth_gravity.y * dt - ((Cx * S * mvEau * Mathf.Pow(mo.vitesse.y, 2) * dt) / (2f * dp.masse)) - (mvEau * V * mo.earth_gravity.y * 0.01f / dp.masse);
                    Debug.Log("delta y");
                    Debug.Log(delta_y);
                    //go.transform.eulerAngles = new Vector3 (0, 0, mo.vitesse.y*Mathf.Rad2Deg );
                }
                else
                {
                    //le projectile a touché le sol -> force de frottement
                    delta_x      += mu * (mo.earth_gravity.y / 2f) * Mathf.Pow(dt, 2);
                    mo.vitesse.x += mu * mo.earth_gravity.y * dt;
                    //go.transform.eulerAngles = new Vector3 (0, 0, mo.vitesse.x*Mathf.Rad2Deg );

                    // si la vitesse est nulle, le projectile ne bouge plus
                    if (mo.vitesse.x <= 0f && mo.vitesse.y <= 0f)
                    {
                        mo.inMovement = false;
                        //faire une pause pour l'affichage
                        go.AddComponent <WaitEau>();
                    }
                }


                go.transform.position += new Vector3(delta_x, delta_y, 0f);
            }
        }
    }
예제 #5
0
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        // gestion des collisions avec le sol et les structures
        foreach (GameObject go in _incollision)
        {
            InCollision2D col = go.GetComponent <InCollision2D> ();

            Move mo = go.GetComponent <Move> ();

            foreach (GameObject target in col.Targets)
            {
                // ground collision
                // quand le projectile ne bouge plus -> nouveau projectile créé donc ne plus toucher à la vitesse
                if (target != null && target.tag.Equals("Ground") && mo.inMovement == true)
                {
                    mo.groundContact = true;
                    mo.vitesse.y     = 0f;
                }

                //mo.inMovement == true pour éviter modification de vitesse quand on remet un nouveau projectile
                if (target.tag.Equals("wood_struct") && mo.inMovement == true && !mo.idStructure.Contains(target.GetInstanceID()))
                {
                    DataProjectile dP = go.GetComponent <DataProjectile> ();
                    Rigidbody2D    rB = target.GetComponent <Rigidbody2D> ();
                    mo.vitesse.x = (mo.vitesse.x * (dP.masse - rB.mass)) / (dP.masse + rB.mass);
                    mo.vitesse.y = (mo.vitesse.y * (dP.masse - rB.mass)) / (dP.masse + rB.mass);
                    mo.idStructure.Add(target.GetInstanceID());
                }

                if (target != null && target.tag.Equals("reward"))
                {
                    Collect co = target.GetComponent <Collect> ();
                    total.score_total += co.reward;
                    GameObjectManager.unbind(target);
                    GameObject.Destroy(target);
                }
            }
        }

        // détection des récompenses et des obstacles
        foreach (GameObject go in _triggered2D)
        {
            Triggered2D tr = go.GetComponent <Triggered2D> ();
            Move        mo = go.GetComponent <Move> ();
            foreach (GameObject target in tr.Targets)
            {
                if (target.tag.Equals("reward"))
                {
                    Collect co = target.GetComponent <Collect> ();
                    total.score_total += co.reward;
                    GameObjectManager.unbind(target);
                    GameObject.Destroy(target);
                }

                if (target.tag.Equals("broken_stone") && mo.inMovement == true && mo.stone_touched == false)
                {
                    mo.vitesse.x = 0;
                    GameObjectManager.unbind(target);
                    GameObject.Destroy(target);
                    mo.stone_touched = true;
                }

                if (target.tag.Equals("stone_struct") && mo.inMovement == true && mo.stone_touched == false)
                {
                    mo.vitesse.x = 0;
                    target.GetComponent <SpriteRenderer> ().sprite = Resources.Load("brokenS", typeof(Sprite)) as Sprite;
                    target.tag       = "broken_stone";
                    mo.stone_touched = true;
                }

                if (target.tag.Equals("obstacle"))
                {
                    mo.vitesse.x = 0;
                }
            }
        }
    }