void Update() { input[0] = Input.GetAxis("Horizontal"); input[1] = Input.GetAxis("Vertical"); input[2] = Input.GetAxis("Rudder"); input[3] = Input.GetAxis("Engine"); AS.SetControlInput(input); }
// Update is called once per frame void Update() { // Check UI buttons if (initialRun || resetOrdered) { ResetEnvironment(); resetOrdered = false; initialRun = false; return; } if (exitOrdered) { agentController.CloseAgent(); Close(); return; } // Execute Physics ExecutePhysics(); // Update state analytics.UpdateAnalytics(); UpdateState(); onStateChange?.Invoke(state); // Calculate reward currentReward += CalculateReward(); // Check done if (touchedDown && !done) { onEpisodeEnded?.Invoke(landingReport); done = true; } if (airplane.position.z < 0) { done = true; } // Get action from agent if (actionSkipCounter == actionFrequency || done) { for (int i = 0; i < actionsOld.Length; i++) { actionsOld[i] = response.actions[i]; } response = agentController.GetActionResponse(0, state, currentReward, done); responseCount++; aircraftScript.SetControlInput(response.actions); onActionValueChange?.Invoke(response.actions); actionSkipCounter = 1; currentReward = 0; } else { actionSkipCounter++; } // Perform configurations received from custom message string in agent response if (response.msg.Length > 0) { //BoxLogUI.instance.Log("Received message from agent: "); foreach (string s in response.msg.Split(messageArgumentSeparator, System.StringSplitOptions.None)) { //BoxLogUI.instance.Log(s); HandleMessage(s); } } // Perform exit or reset on environment if told so by agent, else run physics if (response.symbol == AgentController.AgentActionSymbol.Exit) { Close(); } else if (response.symbol == AgentController.AgentActionSymbol.Reset) { resetOrdered = true; } }