Ejemplo n.º 1
0
    void Awake()
    {
        agentFellOutOfMapThreshold = transform.position.y - 10f;
        enemies          = new List <GameObject>();
        enemiesHealth    = new List <Health>();
        enemiesInitState = new List <InitGOState>();
        enemiesEnemy     = new List <Enemy>();
        enemiesView      = new List <AIView>();

        foreach (Transform child in transform)
        {
            if (child.tag == "Enemy")
            {
                enemies.Add(child.gameObject);
                enemiesHealth.Add(child.gameObject.GetComponent <Health>());
                enemiesInitState.Add(CreateInitGOState(child.gameObject));
                enemiesEnemy.Add(child.gameObject.GetComponent <Enemy>());
                enemiesView.Add(child.gameObject.GetComponent <AIView>());
            }
            else if (child.tag == "Player")
            {
                agent          = child.gameObject;
                agentInitState = CreateInitGOState(agent);
            }
        }
        agentHealth       = agent.GetComponent <Health>();
        agentScore        = agent.GetComponent <Score>();
        agentStateCapture = agent.GetComponent <StateCapture>();
    }
Ejemplo n.º 2
0
    public void RestartEpisode()
    {
        curTimeStep   = 0;
        shouldRestart = false;
        ResetReward();
        lastRewardApplied = false;
        isEpisodeOver     = false;
        agentStateCapture.sentEpisodeOver = false;

        // Reset initial state of agent and enemies
        agent.transform.position = new Vector3(agentInitState.position.x, agentInitState.position.y, agentInitState.position.z);
        agent.transform.rotation = new Quaternion(agentInitState.rotation.x, agentInitState.rotation.y, agentInitState.rotation.z, agentInitState.rotation.w);
        agentHealth.health       = agentHealth.startingHealth;

        for (int i = 0; i < enemies.Count; i++)
        {
            InitGOState curState = enemiesInitState[i];
            enemies[i].transform.position = new Vector3(curState.position.x, curState.position.y, curState.position.z);
            enemies[i].transform.rotation = new Quaternion(curState.rotation.x, curState.rotation.y, curState.rotation.z, curState.rotation.w);
            enemiesEnemy[i].enabled       = true;
            enemiesView[i].enabled        = true;
            enemiesHealth[i].health       = enemiesHealth[i].startingHealth;
            enemiesHealth[i].ResetHealthSlider();
        }
        agentStateCapture.shouldSendState = true;
        //Application.LoadLevel(Application.loadedLevel);
    }