Esempio n. 1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            startKick();
            startKicked = true;
        }
        //APLICAMOS LA ROTACION A LA PELOTA A PARTIR DE FTAU
        transform.Rotate(new Vector3(fTau.x, fTau.y, fTau.z), wVelocity.Module());                                                                                                                                   //PARA ROTAR PASAMOS EL EJE DE ROTACION Y EL MODULO DE HOMEGA
        Debug.DrawLine(new Vector3(transform.position.x, transform.position.y, transform.position.z), new Vector3(VectorDireccion.position.x, VectorDireccion.position.y, VectorDireccion.position.z), Color.black); //VEC DIRECCION IMPACTO
        Debug.DrawRay(transform.position, new Vector3(fTau.x, fTau.y, fTau.z), Color.black);                                                                                                                         //VECTOR DIR HOMEGA, EJE DE ROTACION

        if (startKicked == true)
        {
            //Calcular fDrag
            fDrag.x = -Kd *lVelocityInit.Module() * lVelocityInit.x;

            fDrag.y = -Kd *lVelocityInit.Module() * lVelocityInit.y;

            fDrag.z = -Kd *lVelocityInit.Module() * lVelocityInit.z;

            //Calcular fMagnus
            Our_Vector3 wVelocityAux = new Our_Vector3(wVelocity.x, wVelocity.y, wVelocity.z);
            wVelocityAux.Normalize();
            fMagnus.x = Km * lVelocityInit.Module() * (wVelocityAux.y * lVelocityInit.z - lVelocityInit.y * wVelocityAux.z);
            fMagnus.y = Km * lVelocityInit.Module() * (wVelocityAux.x * lVelocityInit.z - lVelocityInit.x * wVelocityAux.z);
            fMagnus.z = Km * lVelocityInit.Module() * (wVelocityAux.x * lVelocityInit.y - lVelocityInit.x * wVelocityAux.y);

            //Agrupar fTotal
            fTotal.x = fDrag.x + fMagnus.x + fGravity.x;
            fTotal.y = fDrag.y + fMagnus.y + fGravity.y;
            fTotal.z = fDrag.z + fMagnus.z + fGravity.z;
            //ACTUALIZAR lVelocityInit A PARTIR DE LAS NUEVAS FORUMLAS CON EL METODO DE EULER
            float aTx = fTotal.x / mass;
            float aTy = fTotal.y / mass;
            float aTz = fTotal.z / mass;
            //Debug.Log("Antes" + lVelocityInit.Module());
            lVelocityFin       = lVelocityInit;
            lVelocityInit.x    = lVelocityFin.x + aTx * Time.deltaTime;
            lVelocityInit.y    = lVelocityFin.y + aTy * Time.deltaTime;
            lVelocityInit.z    = lVelocityFin.z + aTz * Time.deltaTime;
            transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z)
                                 + new Vector3(lVelocityFin.x, lVelocityFin.y, lVelocityFin.z) * Time.deltaTime;
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        // 0.5   ---  3
        Our_Vector3 dist = new Our_Vector3(pelota.transform.position.x - transform.position.x, pelota.transform.position.y - transform.position.y, pelota.transform.position.z - transform.position.z);

        Debug.DrawLine(pelota.transform.position, transform.position, Color.green);
        if (dist.Module() < 0.2)
        {
            //Debug.Log("Col");
            gravity.y       = 0;
            Welocity.module = 0;
            Welocity.x      = 0;
            Welocity.y      = 0;
            Welocity.z      = 0;
            tau.x           = 0;
            tau.y           = 0;
            tau.z           = 0;
            velocityP.x     = 0;
            velocityP.y     = 0;
            velocityP.z     = 0;
        }
        //Debug.Log(velocityP.x);
    }
Esempio n. 3
0
    void Update()
    {
        if (!done)
        {
            if (intentos <= M_intentos)
            {
                for (int i = joints.Length - 1; i >= 0; i--) //AQUI ESTABA -2 !!!
                {
                    Our_Vector3 r1 = new Our_Vector3(0, 0, 0);
                    r1.x = joints[joints.Length - 1].transform.position.x - joints[i].transform.position.x;
                    r1.y = joints[joints.Length - 1].transform.position.y - joints[i].transform.position.y;
                    r1.z = joints[joints.Length - 1].transform.position.z - joints[i].transform.position.z;
                    Our_Vector3 r2 = new Our_Vector3(0, 0, 0);
                    r2.x = targetPosition.x - joints[i].transform.position.x;
                    r2.y = targetPosition.y - joints[i].transform.position.y;
                    r2.z = targetPosition.z - joints[i].transform.position.z;
                    if (r1.Module() * r2.Module() <= 0.001f)
                    {
                    }
                    else
                    {
                        cos[i] = r1.DotProduct(r2) / (r1.Module() * r2.Module());
                        sin[i] = r1.CrossProduct(r2).Module() / (r1.Module() * r2.Module());
                    }

                    Our_Vector3 rotationAxis = rotationAxis = r1.CrossProduct(r2);
                    rotationAxis.Normalize();

                    if (type == "cadera")
                    {
                        if (i == 0)
                        {
                            theta[i] = Mathf.Acos(cos[i]);
                            theta[i] = theta[i] * Mathf.Rad2Deg;
                            if (sin[i] < 0)
                            {
                                theta[i] = -theta[i];
                            }

                            Our_Quaternion rt         = new Our_Quaternion(joints[i].transform.rotation.x, joints[i].transform.rotation.y, joints[i].transform.rotation.z, joints[i].transform.rotation.w);
                            Our_Quaternion myRotation = new Our_Quaternion(theta[i], rotationAxis); //ESTO FALLA
                            myRotation.Multiply(rt);
                            myRotation.y = myRotation.z = 0;                                        //Rotation only in X axis.
                            Quaternion temp = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);

                            float   angleF;
                            Vector3 axisF;
                            temp.ToAngleAxis(out angleF, out axisF);
                            if (angleF > 130 && angleF < 230)
                            {
                                joints[i].transform.rotation = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);
                            }
                        }
                    }

                    if (type == "brazoD")
                    {
                        if (i == 0)
                        {
                            theta[i] = Mathf.Acos(cos[i]);
                            theta[i] = theta[i] * Mathf.Rad2Deg;
                            if (sin[i] < 0)
                            {
                                theta[i] = -theta[i];
                            }

                            Our_Quaternion rt         = new Our_Quaternion(joints[i].transform.rotation.x, joints[i].transform.rotation.y, joints[i].transform.rotation.z, joints[i].transform.rotation.w);
                            Our_Quaternion myRotation = new Our_Quaternion(theta[i], rotationAxis); //ESTO FALLA
                            myRotation.Multiply(rt);
                            myRotation.y = myRotation.z = 0;                                        //Rotation only in X axis.
                            Quaternion temp = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);

                            float   angleF;
                            Vector3 axisF;
                            temp.ToAngleAxis(out angleF, out axisF);
                            if (angleF > 15 && angleF < 270)
                            {
                                joints[i].transform.rotation = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);
                            }
                        }

                        if (i == 1)
                        {
                            theta[i] = Mathf.Acos(cos[i]);
                            theta[i] = theta[i] * Mathf.Rad2Deg;
                            if (sin[i] < 0)
                            {
                                theta[i] = -theta[i];
                            }

                            Our_Quaternion rt         = new Our_Quaternion(joints[i].transform.rotation.x, joints[i].transform.rotation.y, joints[i].transform.rotation.z, joints[i].transform.rotation.w);
                            Our_Quaternion myRotation = new Our_Quaternion(theta[i], rotationAxis); //ESTO FALLA
                            myRotation.Multiply(rt);
                            myRotation.y = myRotation.z = 0;                                        //Rotation only in X axis.
                            Quaternion temp = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);

                            float   angleF;
                            Vector3 axisF;
                            temp.ToAngleAxis(out angleF, out axisF);
                            if (angleF > 10 && angleF < 90)
                            {
                                joints[i].transform.rotation = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);
                            }
                        }
                    }

                    if (type == "brazoI")
                    {
                        if (i == 0)
                        {
                            theta[i] = Mathf.Acos(cos[i]);
                            theta[i] = theta[i] * Mathf.Rad2Deg;
                            if (sin[i] < 0)
                            {
                                theta[i] = -theta[i];
                            }

                            Our_Quaternion rt         = new Our_Quaternion(joints[i].transform.rotation.x, joints[i].transform.rotation.y, joints[i].transform.rotation.z, joints[i].transform.rotation.w);
                            Our_Quaternion myRotation = new Our_Quaternion(theta[i], rotationAxis); //ESTO FALLA
                            myRotation.Multiply(rt);
                            myRotation.y = myRotation.z = 0;                                        //Rotation only in X axis.
                            Quaternion temp = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);

                            float   angleF;
                            Vector3 axisF;
                            temp.ToAngleAxis(out angleF, out axisF);
                            if (angleF > 90 && angleF < 345)
                            {
                                joints[i].transform.rotation = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);
                            }
                        }
                        if (i == 1)
                        {
                            theta[i] = Mathf.Acos(cos[i]);
                            theta[i] = theta[i] * Mathf.Rad2Deg;
                            if (sin[i] < 0)
                            {
                                theta[i] = -theta[i];
                            }

                            Our_Quaternion rt         = new Our_Quaternion(joints[i].transform.rotation.x, joints[i].transform.rotation.y, joints[i].transform.rotation.z, joints[i].transform.rotation.w);
                            Our_Quaternion myRotation = new Our_Quaternion(theta[i], rotationAxis); //ESTO FALLA
                            myRotation.Multiply(rt);
                            myRotation.y = myRotation.z = 0;                                        //Rotation only in X axis.
                            Quaternion temp = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);

                            float   angleF;
                            Vector3 axisF;
                            temp.ToAngleAxis(out angleF, out axisF);
                            if (angleF > 50 && angleF > 270)
                            {
                                joints[i].transform.rotation = new Quaternion(myRotation.x, myRotation.y, myRotation.z, myRotation.w);
                            }
                        }
                    }
                }
                intentos++;
            }
        }
        float f = (targetPosition.x - joints[joints.Length - 1].transform.position.x + targetPosition.y - joints[joints.Length - 1].transform.position.y + targetPosition.z - joints[joints.Length - 1].transform.position.z);

        if (f < rango)
        {
            done = true;
        }
        else
        {
            done = false;
        }                                                                                                                                                          //End effector esta lo suficientemente cerca del target

        if (targetPosition.x != target.transform.position.x || targetPosition.y != target.transform.position.y || targetPosition.z != target.transform.position.z) //targetPosition != target.transform.position
        {
            intentos         = 0;
            targetPosition.x = target.transform.position.x;
            targetPosition.y = target.transform.position.y;
            targetPosition.z = target.transform.position.z;
        }
    }