Пример #1
0
    // Update is called once per frame
    void Update()
    {
        hasFailed = hit.crash;

        //update raycast hit distance
        l  = raycast.dis_l;
        fl = raycast.dis_fl;
        f  = raycast.dis_f;
        fr = raycast.dis_fr;
        r  = raycast.dis_fr;


        if (!hasFailed)
        {
            dist += Time.deltaTime;
            List <float> inputs = new List <float> ();
            inputs.Add(Normalise(l));
            inputs.Add(Normalise(fl));
            inputs.Add(Normalise(f));
            inputs.Add(Normalise(fr));
            inputs.Add(Normalise(r));

            neuralnet.SetInput(inputs);
            neuralnet.refresh();

            leftForce  = neuralnet.GetOutput(0);
            rightForce = neuralnet.GetOutput(1);

            leftTheta  = MAX_ROTATION * leftForce;
            rightTheta = MAX_ROTATION * rightForce;

            headingAngle += (leftTheta - rightTheta) * Time.deltaTime;

            float speed = (Mathf.Abs(leftForce + rightForce)) / 2;
            speed *= _SPEED;

            speed = Clamp(speed, -_SPEED, _SPEED);
        }
        else
        {
            dist = 0.0f;
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        hasFailed = hit.HasCrashed();

        if (!freezeMotion && !hasFailed)
        {
            totalTime += Time.deltaTime;

            List <float> inputs = new List <float> ();
            inputs.Add(NormaliseSpeed(currSpeed));
            inputs.Add(Normalise(sensor.Getdis_fl()));
            inputs.Add(Normalise(sensor.Getdis_f()));
            inputs.Add(Normalise(sensor.Getdis_fr()));

            neuralnet.SetInput(inputs);
            neuralnet.refresh();

            ///////ROTATION//////////
            float thetaChange = neuralnet.GetOutput(0);
            //These values go from 0 to 1, so lets map them
            thetaChange += -0.5f;          //shift down by 0.5, so it goes from -0.5 to 0.5
            thetaChange *= 2f;             //double, so it goes from -1 to 1

            transform.Rotate(new Vector3(0, MAX_ROTATION * thetaChange * Time.deltaTime, 0));

            ///////TRANSLATION//////////
            float acceleration = neuralnet.GetOutput(1);
            //These values go from 0 to 1, so lets map them
            acceleration *= 2f;             //double, so it goes from 0 to 2
            acceleration -= 1f;             //shift down by 1, so it goes from -1 to 1

            //Keep a running total of the speed
            currSpeed += ACCEL_FACTOR * acceleration * Time.deltaTime;
            currSpeed  = Clamp(currSpeed, MIN_SPEED, MAX_SPEED);

            float   dir   = (Mathf.PI * transform.rotation.eulerAngles.y) / 180;         //convert to radians
            Vector3 newsp = new Vector3(currSpeed * Mathf.Cos(dir), 0, -currSpeed * Mathf.Sin(dir));

            transform.position = transform.position + (newsp * Time.deltaTime);
        }
    }