Ejemplo n.º 1
0
    private void Update()
    {
        ConveyorLineMotorValue = m_LineVariables_script.GetBool(ConveyorLineMotorByte, ConveyorLineMotorBit);//We get the actual value
        // Scroll texture to fake it moving
        if (ConveyorLineMotorValue)
        {
            if (HighSpeedCounterLineValue + (int)(2048 * (Time.deltaTime * desiredspeed) / 0.942f) < 100000)
            {
                HighSpeedCounterLineValue = HighSpeedCounterLineValue + (int)(2048 * (Time.deltaTime * desiredspeed * 2) / 0.942f);
            }
            else
            {
                HighSpeedCounterLineValue = HighSpeedCounterLineValue + (int)(2048 * (Time.deltaTime * desiredspeed * 2) / 0.942f) - 100000;
            }

            m_LineVariables_script.SetIntDec(HighSpeedCounterLineByte, HighSpeedCounterLineValue); // We set the encoder value

            //currentScroll = currentScroll + Time.deltaTime * desiredspeed * visualSpeedScalar;
            //GetComponent<Renderer>().material.mainTextureOffset = new Vector2(0, currentScroll);
        }
        if (Input.GetKeyDown("o"))
        {
            AllowTheMovement = !AllowTheMovement;
        }
    }
Ejemplo n.º 2
0
    void FixedUpdate()
    {
        //Make the movement!
        //------------------------------------------------------------
        //X movement
        float xSpeed = 0.85f;

        if (Manipulator_xAxisMotorLowSpeedValue)
        {
            xSpeed = 0.2f;
        }
        else
        {
            xSpeed = 0.5f;
        }
        if (Manipulator_xAxisMotorForwardValue)
        {
            AddMoveX(1 * xSpeed);
        }
        if (Manipulator_xAxisMotorReversalValue)
        {
            AddMoveX(-1 * xSpeed);
        }
        //------------------------------------------------------------
        //Z movement
        float zSpeed = 0.0120f;

        Check_case1      = System.Convert.ToInt32(Manipulator_zAxisMotorSpeed1Value);
        Check_case2      = System.Convert.ToInt32(Manipulator_zAxisMotorSpeed2Value);
        Check_case3      = System.Convert.ToInt32(Manipulator_zAxisMotorSpeed3Value);
        Check_case1_DISP = System.Convert.ToInt32(Manipulator_zAxisMotorSpeed1Value) << 2;
        Check_case2_DISP = System.Convert.ToInt32(Manipulator_zAxisMotorSpeed2Value) << 1;
        Check_case       = Check_case1_DISP + Check_case2_DISP + Check_case3;
        switch (Check_case)
        {
        case 0:    //0 0 0  -> 12Hz
            zSpeed = zSpeed * 10f;
            break;

        case 1:    //0 0 1
            break;

        case 2:    //0 1 0  -> 6.3Hz
            zSpeed = zSpeed * 5.3f;
            break;

        case 3:    //0 1 1  ->
            break;

        case 4:    //1 0 0  ->
            zSpeed = zSpeed * 50f;
            break;

        case 5:    //1 0 1  -> 45Hz
            zSpeed = zSpeed * 45f;
            break;

        case 6:    //1 1 0  ->
            break;

        case 7:    //1 1 1  ->
            break;

        default:    //wutt?
            break;
        }

        if (Manipulator_zAxisMotorForwardValue)
        {
            AddMoveZ(-1 * zSpeed);
            if (GameObject_sucker_script.Collision == false)
            {
                AddMoveZ_Suckers(-1 * zSpeed);
            }
        }
        if (Manipulator_zAxisMotorReversalValue)
        {
            AddMoveZ(1 * zSpeed);
            if ((GameObject_sucker[0].transform.position.y - GameObject_w.transform.position.y) < 0)
            {
                AddMoveZ_Suckers(1 * zSpeed);
            }
        }
        //------------------------------------------------------------
        //W movement
        float wSpeedF = -3f;
        float wSpeedB = -3f;

        Manipulator_wAxisSpeedWriteValue_CASTED = Manipulator_wAxisSpeedWriteValue;
        if (Manipulator_wAxisSpeedWriteValue > 33268)
        {
            Manipulator_wAxisSpeedWriteValue_CASTED = (Manipulator_wAxisSpeedWriteValue - 65536);
        }
        if (Manipulator_ServoMotorStartValue && Manipulator_wAxisSpeedWriteValue_CASTED > 0)
        {
            AddMoveW(wSpeedF * Manipulator_wAxisSpeedWriteValue_CASTED / 33268f);                                                                                             //FORWARD
        }
        if (Manipulator_ServoMotorStartValue && Manipulator_wAxisSpeedWriteValue_CASTED < 0)
        {
            AddMoveW(wSpeedB * Manipulator_wAxisSpeedWriteValue_CASTED / 33268f);                                                                                             //bACKWARS
        }
        //------------------------------------------------------------

        float ZAdjustFactor = 1f;

        if (Manipulator_zAxisMotorForwardValue && !Manipulator_zAxisMotorReversalValue)
        {
            //Manipulator_HighSpeedCounterValue = Manipulator_HighSpeedCounterValue + (int)(ZAdjustFactor * 2048 * (Time.deltaTime * zSpeed) / 0.2805f);
            Manipulator_HighSpeedCounterValue = (int)(2048 * (StartingZPosition - GameObject_z.GetComponent <Rigidbody>().position.y) / 0.2805f);
        }
        else if (Manipulator_zAxisMotorReversalValue && !Manipulator_zAxisMotorForwardValue)
        {
            //Manipulator_HighSpeedCounterValue = Manipulator_HighSpeedCounterValue - (int)(ZAdjustFactor * 2048 * (Time.deltaTime * zSpeed) / 0.2805f);
            Manipulator_HighSpeedCounterValue = (int)(2048 * (StartingZPosition - GameObject_z.GetComponent <Rigidbody>().position.y) / 0.2805f);
        }
        //if (m_Z_Origin_script.SensorValue == true) Manipulator_HighSpeedCounterValue = 0;
        if (Manipulator_HighSpeedCounterValue < 0)
        {
            Manipulator_HighSpeedCounterValue = -1;
        }
        m_LineVariables_script.SetIntDec(Manipulator_HighSpeedCounterByte, (int)(ZAdjustFactor * Manipulator_HighSpeedCounterValue)); // We set the encoder value

        //currentScroll = currentScroll + Time.deltaTime * desiredspeed * visualSpeedScalar;
        //GetComponent<Renderer>().material.mainTextureOffset = new Vector2(0, currentScroll);


        if (Input.GetKey("t"))
        {
            AddMoveZ(1 * zSpeed);
            //if()
            if ((GameObject_sucker[0].transform.position.y - GameObject_w.transform.position.y) < 0)
            {
                AddMoveZ_Suckers(1 * zSpeed);
            }
        }
        else if (Input.GetKey("g"))
        {
            AddMoveZ(-1 * zSpeed);
            if (GameObject_sucker_script.Collision == false)
            {
                AddMoveZ_Suckers(-1 * zSpeed);
            }
        }
        else if (Input.GetKey("f"))
        {
            AddMoveX(1 * xSpeed);
        }
        else if (Input.GetKey("h"))
        {
            AddMoveX(-1 * xSpeed);
        }
        else if (Input.GetKey("y"))
        {
            AddMoveW(0.08f * wSpeedF);
        }
        else if (Input.GetKey("v"))
        {
            AddMoveW(-0.08f * wSpeedF);
        }


        Vector3 Movement_x = new Vector3(GameObject_x_movement, 0, 0);
        Vector3 Movement_z = new Vector3(GameObject_x_movement, GameObject_y_movement, 0);
        Vector3 Movement_w = new Vector3(GameObject_x_movement, GameObject_y_movement, GameObject_z_movement);


        Vector3 Movement_sucker = new Vector3(GameObject_x_movement, GameObject_y_suckers_movement, GameObject_z_movement);

        GameObject_x.GetComponent <Rigidbody>().MovePosition(GameObject_x.GetComponent <Rigidbody>().position + Movement_x);
        GameObject_z.GetComponent <Rigidbody>().MovePosition(GameObject_z.GetComponent <Rigidbody>().position + Movement_z);
        GameObject_w.GetComponent <Rigidbody>().MovePosition(GameObject_w.GetComponent <Rigidbody>().position + Movement_w);
        for (int i = 0; i < GameObject_sucker.Length; i++)
        {
            GameObject_sucker[i].GetComponent <Rigidbody>().MovePosition(GameObject_sucker[i].GetComponent <Rigidbody>().position + Movement_sucker);
        }

        GameObject_x_movement         = 0;
        GameObject_y_movement         = 0;
        GameObject_z_movement         = 0;
        GameObject_y_suckers_movement = 0;
    }