Esempio n. 1
0
    //public bool showParticles = true;

    //public GameObject[] thrusterClockwise;
    //public GameObject[] thrusterCounterClockwise;

    // Start is called before the first frame update
    void Start()
    {
        desired_angle = 0;
        lightSensors  = GetComponentsInChildren <LightSensor2>();
        solarPanels   = GetComponentsInChildren <SolarPanel2>();

        rgbd = GetComponent <Rigidbody>();

        //pidRotate = new PIDController(0.000001f, 0.025f, 0.0000f);
        pidRotate = new PIDController(5f, 1f, 0.01f);
        //pidRotate = new PIDController(1f, 0f, 0f);
        //pidRotate = new PIDController(1f, 0.001f, 0.001f);
        //pidRotate = new PIDController(0.001f, 0f, 0f);

        //AnimateThrusters(thrusterClockwise, false);
        //AnimateThrusters(thrusterCounterClockwise, false);

        socket = FindObjectOfType <NetworkHandler>().client;

        socket.On("connect", () =>
        {
            //socket.FillSendBuffer<string>("u","\"float\"");
            socket.FillSendBuffer <string>("actual_angle", "\"float\"");
            socket.FillSendBuffer <string>("desired_angle", "\"float\"");
            socket.SendAvailableData();
        });
    }
Esempio n. 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //desired_angle =
        Vector3 vecToSun             = CalculatedSolarDir();
        Vector3 desiredSolarPanelDir = Vector3.ProjectOnPlane(vecToSun, transform.right);
        Vector3 desiredRotateDir     = Vector3.ProjectOnPlane(vecToSun, transform.up);

        Debug.DrawRay(transform.position, desiredSolarPanelDir * 3, Color.magenta);
        Debug.DrawRay(transform.position, desiredRotateDir * 3, Color.green);

        //if (showParticles)
        //{
        //    AnimateThrusters(thrusterClockwise, true);
        //    AnimateThrusters(thrusterCounterClockwise, true);
        //}
        //else
        //{
        //    AnimateThrusters(thrusterClockwise, false);
        //    AnimateThrusters(thrusterCounterClockwise, false);
        //}

        //Debug.DrawRay(transform.position, (sun.position - transform.position).normalized * 5f, Color.white);

        //if (rotateClockwise)
        //{
        //    rgbd.AddRelativeTorque(transform.up, ForceMode.Acceleration);
        //}
        //else
        //{
        //    rgbd.AddRelativeTorque(-transform.up, ForceMode.Acceleration);
        //}
        if (!disableRotate)
        {
            HandleRotate(desiredRotateDir);
        }
        if (!disableSolarPanel)
        {
            HandleSolarPanels(desiredSolarPanelDir);
        }
        socket.FillSendBuffer <float>("actual_angle", Vector3.SignedAngle(transform.forward, Vector3.right, Vector3.up));
        socket.FillSendBuffer <float>("desired_angle", Vector3.SignedAngle(desiredRotateDir, Vector3.right, Vector3.up));
        socket.SendBuffer();
    }