コード例 #1
0
 // Update is called once per frame
 void Update()
 {
     if (my_num == 0)
     {
         num_falcons = FalconUnity.getNumFalcons();
         FalconUnity.Update();
     }
 }
コード例 #2
0
    void Start()
    {
//		FalconUnity.setForceField(0, new float[] {0,-10,0});
        if (my_num == 0)
        {
            num_falcons = FalconUnity.getNumFalcons();
            if (FalconUnity.IsRemote())
            {
                FalconUnity.Update();
            }
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        Vector3 tipPosition = new Vector3();         // Tip position projected on the camera, used for Falcon movement

        if (FalconUnity.getNumFalcons() > 0)
        {
            usingFalcon = true;
            tipPosition = cam.WorldToViewportPoint(tip.transform.position);
        }
        else
        {
            usingFalcon = false;
        }

        // TOWER ROTATION
        float deltaTowerRotationSpeed = towerRotationSpeed * Time.deltaTime;

        if (usingFalcon)
        {
            if (tipPosition.x > midpoint + horizontalThreshold)
            {
                tower.transform.Rotate(Vector3.up, deltaTowerRotationSpeed);
            }
            else if (tipPosition.x < midpoint - horizontalThreshold)
            {
                tower.transform.Rotate(Vector3.up, -deltaTowerRotationSpeed);
            }
        }
        else
        {
            var dir = Input.GetAxis("Horizontal");
            tower.transform.Rotate(Vector3.up, dir * deltaTowerRotationSpeed);
        }

        //BARREL ADJUSTMENT (VERTICAL)
        float deltaBarrelRotationSpeed = barrelRotationSpeed * Time.deltaTime;
        float angle = barrelJoint.transform.localEulerAngles.x;

        if (usingFalcon)
        {
            if (tipPosition.y > midpoint + verticalThreshold)              // MOVE UP
            {
                barrelJoint.transform.Rotate(-barrelJoint.transform.right, deltaBarrelRotationSpeed, Space.World);
            }
            else if (tipPosition.y < midpoint - verticalThreshold)                // MOVE DOWN
            {
                barrelJoint.transform.Rotate(barrelJoint.transform.right, deltaBarrelRotationSpeed, Space.World);
            }
        }
        else
        {        //no falcon
            var dir = Input.GetAxis("Vertical");
            barrelJoint.transform.Rotate(barrelJoint.transform.right, -dir * deltaBarrelRotationSpeed, Space.World);

            if (angle < 70)
            {
                // Rotate back
                barrelJoint.transform.Rotate(barrelJoint.transform.right, dir * deltaBarrelRotationSpeed * 2, Space.World);
            }
        }
    }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        num_falcons = FalconUnity.getNumFalcons();
        FalconUnity.Update();

        if (contador.fuerza == 0)
        {
            if (!haveReceivedTipPosition)
            {
                Vector3 posTip2;
                bool    result = FalconUnity.getTipPosition(falcon_num, out posTip2);
                if (!result)
                {
                    //				Debug.Log("Error getting tip position");
                    return;
                }
                receivedCount++;

                if (receivedCount < 25 && (posTip2.x == 0 && posTip2.y == 0 && posTip2.z == 0))
                {
                    return;
                }

                //hapticTip.position = posTip2;

                //godObject.position = posTip2;
                hapticTip.position = new Vector3(posTip2.x, posTip2.y, posTip2.z);//posTip2.z

                godObject.position = new Vector3(posTip2.x, posTip2.y, posTip2.z);

                Debug.Log("Initialized with tip position: ");
                Debug.Log(posTip2);
                FalconUnity.setSphereGodObject(falcon_num, godObject.localScale.x * godObject.GetComponent <SphereCollider>().radius, godObjectMass, godObject.position, minDistToMaxForce * hapticTipToWorldScale, maxDistToMaxForce * hapticTipToWorldScale);

                haveReceivedTipPosition = true;
            }

            Vector3 tipPositionScale = new Vector3(1, 1, -1);
            tipPositionScale *= hapticTipToWorldScale;

            if (savedHapticTipToWorldScale != hapticTipToWorldScale)
            {
                FalconUnity.setSphereGodObject(falcon_num, godObject.localScale.x * godObject.GetComponent <SphereCollider>().radius, godObjectMass, godObject.position, minDistToMaxForce * hapticTipToWorldScale, maxDistToMaxForce * hapticTipToWorldScale);
                savedHapticTipToWorldScale = hapticTipToWorldScale;
            }

            FalconUnity.updateHapticTransform(falcon_num, new Vector3(transform.position.x, transform.position.y, 0), transform.rotation, tipPositionScale, useMotionCompensator, Time.deltaTime);

            Vector3 posGod;
            bool    res = FalconUnity.getGodPosition(falcon_num, out posGod);
            if (!res)
            {
                //			Debug.Log("Error getting god tip position");
                return;
            }
            Vector3 posTip;
            res = FalconUnity.getTipPosition(falcon_num, out posTip);
            if (!res)
            {
                //			Debug.Log("Error getting tip position");
                return;
            }
            hapticTip.position = posTip;

            godObject.position = posGod;
            manito.position    = posGod;

            godObject.rotation = new Quaternion(0, 0, 0, 1);

            //	FalconUnity.setForceField(falcon_num,force);
        }
        else
        {
            Debug.Log("notomaposicion");
        }
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        if (contador.b_instanciar == 0)
        {
            aux1 = 0;
        }
        if (contador.b_instanciar == 0 && aux2 == 0)
        {
            aux2 = 1;
            FalconUnity.setSphereGodObject(falcon_num, godObject.localScale.x * godObject.GetComponent <SphereCollider>().radius, godObjectMass, godObject.position, minDistToMaxForce * hapticTipToWorldScale, maxDistToMaxForce * hapticTipToWorldScale);
        }


        if (contador.b_instanciar == 1 && aux1 == 0)
        {
            aux  = 0;
            aux2 = 0;
        }


        if (aux == 0)
        {
            FalconUnity.setSphereGodObject(falcon_num, godObject.localScale.x * godObject.GetComponent <SphereCollider>().radius, godObjectMass, godObject.position, minDistToMaxForce * hapticTipToWorldScale, maxDistToMaxForce * hapticTipToWorldScale);
            aux  = 1;
            aux1 = 1;
            aux2 = 0;
        }


        num_falcons = FalconUnity.getNumFalcons();
        FalconUnity.Update();



        if (contador.ganador_consultorio == 0)
        {
            if (!haveReceivedTipPosition)
            {
                Vector3 posTip2;
                bool    result = FalconUnity.getTipPosition(falcon_num, out posTip2);
                if (!result)
                {
                    //				Debug.Log("Error getting tip position");
                    return;
                }
                receivedCount++;

                if (receivedCount < 25 && (posTip2.x == 0 && posTip2.y == 0 && posTip2.z == 0))
                {
                    return;
                }

                //hapticTip.position = posTip2;

                //godObject.position = posTip2;
                hapticTip.position = new Vector3(posTip2.x, posTip2.y, posTip2.z);//posTip2.z

                godObject.position = new Vector3(posTip2.x, posTip2.y, posTip2.z);

                Debug.Log("Initialized with tip position: ");
                Debug.Log(posTip2);
                FalconUnity.setSphereGodObject(falcon_num, godObject.localScale.x * godObject.GetComponent <SphereCollider>().radius, godObjectMass, godObject.position, minDistToMaxForce * hapticTipToWorldScale, maxDistToMaxForce * hapticTipToWorldScale);

                haveReceivedTipPosition = true;
            }

            Vector3 tipPositionScale = new Vector3(1, 1, -1);
            tipPositionScale *= hapticTipToWorldScale;

            if (savedHapticTipToWorldScale != hapticTipToWorldScale)
            {
                FalconUnity.setSphereGodObject(falcon_num, godObject.localScale.x * godObject.GetComponent <SphereCollider>().radius, godObjectMass, godObject.position, minDistToMaxForce * hapticTipToWorldScale, maxDistToMaxForce * hapticTipToWorldScale);
                //FalconUnity.updateDynamicShape(contador.cuerpo, 0.001f, 0.01f,godObject.transform.localScale, new Vector3(0, 0, 0), 0.8f);
                savedHapticTipToWorldScale = hapticTipToWorldScale;
            }

            FalconUnity.updateHapticTransform(falcon_num, new Vector3(transform.position.x, transform.position.y, 0), transform.rotation, tipPositionScale, useMotionCompensator, Time.deltaTime);

            Vector3 posGod;
            bool    res = FalconUnity.getGodPosition(falcon_num, out posGod);
            if (!res)
            {
                //			Debug.Log("Error getting god tip position");
                return;
            }
            Vector3 posTip;
            res = FalconUnity.getTipPosition(falcon_num, out posTip);
            if (!res)
            {
                //			Debug.Log("Error getting tip position");
                return;
            }
            hapticTip.position = posTip;

            godObject.position = posGod;
            // manito.position = posGod;

            godObject.rotation = new Quaternion(0, 0, 0, 1);

            camara.position = godObject.position;
        }
        else
        {
        }
    }