Exemplo n.º 1
0
    void Update()
    {
        if (!trainingDone)
        {
            return;
        }

        List <double> calcOutputs = new List <double>();
        List <double> inputs      = new List <double>();
        List <double> outputs     = new List <double>();

        float fDist = 0, rDist = 0, lDist = 0, r45Dist = 0, l45Dist = 0;

        kart.PerformRayCasts(out fDist, out rDist, out lDist, out r45Dist, out l45Dist, this.transform);

        inputs.Add(fDist);
        inputs.Add(rDist);
        inputs.Add(lDist);
        inputs.Add(r45Dist);
        inputs.Add(l45Dist);
        outputs.Add(0);
        outputs.Add(0);
        calcOutputs = ann.CalcOutput(inputs, outputs);

        float translationInput = Utils.Map(-1, 1, 0, 1, (float)calcOutputs[0]);
        float rotationInput    = Utils.Map(-1, 1, 0, 1, (float)calcOutputs[1]);

        kart.Move(this.transform, translationInput, rotationInput);
    }