void Update() { float vAxis = Input.GetAxisRaw("Vertical"); if (vAxis > 0) { critterMotor.MoveForward(); } else { critterMotor.Stop(); } float hAxis = Input.GetAxisRaw("Horizontal"); if (hAxis > 0) { critterMotor.TurnRight(); } else if (hAxis < 0) { critterMotor.TurnLeft(); } else { critterMotor.StopTurning(); } }
void FixedUpdate() { float normalizedLife = critterSensors.SampleLife() / 100f; float normalizedAntenaL = 5f / critterSensors.SampleAntenaL(); float normalizedAntenaR = 5f / critterSensors.SampleAntenaR(); float antenaDiferential = critterSensors.SampleAntenaL() - critterSensors.SampleAntenaR(); float[] input = new float[] { normalizedLife, antenaDiferential, critterSensors.SampleAntenaL() }; float[] output = neuralNetwork.Query(input); float vAxis = output[0]; if (vAxis > 0.5f) { critterMotor.MoveForward(); } else { critterMotor.Stop(); } float hAxis = output[1]; if (hAxis > 0.66f) { critterMotor.TurnRight(); } else if (hAxis < 0.33f) { critterMotor.TurnLeft(); } else { critterMotor.StopTurning(); } }