public void InitializeFromGame(GameObject selfObj, GameObject childObj) { this.observedAction = new ObservedAction(); this.observedAction.InitializeFromGame(); this.gameStateSummary = new GameStateSummary(this.goal); this.gameStateSummary.InitializeFromGame(selfObj, childObj); }
public void InitializeFromSaved(string s) { string[] splits = s.Split('|'); this.gameStateSummary = new GameStateSummary(this.goal); this.gameStateSummary.InitializeFromSaved(splits [0]); this.observedAction = new ObservedAction(); this.observedAction.InitializeFromSaved(splits [1]); }
/// <summary> /// Overwrites the parent rotation input; basically this is called every frame to /// get the inputs to the first person controller /// </summary> protected override void GetRotationInput(bool usingJoystick) { GameStateSummary gss = new GameStateSummary(this.goal); gss.InitializeFromGame(GameObject.Find("AIController(Clone)"), GameObject.Find("AIFirstPersonCharacter")); ObservedAction action = this.network.GetPredictedAction(gss); // uncomment to print current action as CSV //Debug.Log (action); this.yInput = action.yRotInput; this.xInput = 0f; //action.xRotInput; //* 5.0f; //this.xInput = 0f; }
public ObservedAction GetPredictedAction(GameStateSummary gss) { double[] input = { gss.XZAngleToObj, gss.YZAngletoObj, gss.distToObj }; double[] output = this.network.Compute(input); ObservedAction action = new ObservedAction(); action.yRotInput = (float)output [0]; action.xRotInput = (float)output [1]; action.horizontalPan = (float)output [2]; action.forwardPan = (float)output [3]; action.fireButtonDown = (float)output [4]; action.sprintButtonDown = (float)output [5]; action.jumpButtonDown = (float)output [6]; return(action); }
protected override void GetInput(out float speed) { // Read input //manually setting //float horizontal = CrossPlatformInputManager.GetAxis("Horizontal"); GameStateSummary gss = new GameStateSummary(this.goalState); gss.InitializeFromGame(this.gameObject, GameObject.Find("AIFirstPersonCharacter")); ObservedAction action = this.network.GetPredictedAction(gss); Debug.Log(string.Format("{0}|{1}", gss.PrettyPrint(), action.PrettyPrint())); this.isJumping = action.jumpButtonDown > 0.5; //TODO: tune these magic thresholds m_IsWalking = !(action.sprintButtonDown > 0.5); float horizontal = action.horizontalPan; //float vertical = CrossPlatformInputManager.GetAxis("Vertical"); float vertical = action.forwardPan; this.isFiring = (action.fireButtonDown > 0.15f); bool waswalking = this.m_IsWalking; // set the desired speed to be walking or running speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed; m_Input = new Vector2(horizontal, vertical); // normalize input if it exceeds 1 in combined length: if (m_Input.sqrMagnitude > 1) { m_Input.Normalize(); } // handle speed change to give an fov kick // only if the player is going to a run, is running and the fovkick is to be used if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0) { StopAllCoroutines(); StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown()); } }