浏览代码

Update gamecontroller and reset logic

/hh-develop-water-balloon-fight
HH 4 年前
当前提交
f7f7f677
共有 5 个文件被更改,包括 110 次插入20 次删除
  1. 2
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/DodgeBall.cs
  2. 3
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/DodgeBallAgent.cs
  3. 123
      Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/DodgeBallGameController.cs
  4. 2
      Project/ProjectSettings/DynamicsManager.asset

2
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/DodgeBall.cs


{
//IF NOT MY TEAM
//PLAYER GOES TO TIMEOUT
if (!col.gameObject.CompareTag("agent"))
if (col.gameObject.CompareTag("ground"))
{
inPlay = false;
}

3
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/DodgeBallAgent.cs


m_AgentRb = GetComponent<Rigidbody>();
input = GetComponent<FPSAgentInput>();
m_GameController = FindObjectOfType<DodgeBallGameController>();
ActiveBallsQueue.Clear();
// Unfreeze();
// Unpoison();
// Unsatiate();

// 2f, Random.Range(-m_MyArea.range, m_MyArea.range))
// + area.transform.position;
transform.rotation = Quaternion.Euler(new Vector3(0f, Random.Range(0, 360)));
currentNumberOfBalls = 0;
SetActiveBalls(0);
// SetResetParameters();

BallUIList[i].gameObject.SetActive(active);
i++;
}
// for (int i = 0; i < numOfBalls; i++)
// {
// var active = i < numOfBalls;

123
Project/Assets/ML-Agents/Examples/FPS_Game/Scripts/DodgeBallGameController.cs


public int NumberOfBallsToSpawn = 10;
public int NumberOfBallsPlayersCanHold = 3;
// [Serializable]
// public class DodgeBallPlayer
// {
// public int teamID;
// public int currentNumberOfBalls;
// public FPSAgent agent;
// public List<DodgeBall> currentlyHeldBalls;
// }
public class DodgeBallPlayer
public class AgentInfo
public int teamID;
public int currentNumberOfBalls;
public FPSAgent agent;
public List<DodgeBall> currentlyHeldBalls;
public DodgeBallAgent Agent;
[HideInInspector]
public Vector3 StartingPos;
[HideInInspector]
public Quaternion StartingRot;
[HideInInspector]
public Rigidbody Rb;
[HideInInspector]
public Collider Col;
void ResetScene()
private bool m_Initialized;
public List<AgentInfo> Team0Players;
public List<AgentInfo> Team1Players;
public List<DodgeBall> dodgeBallsListTeamO;
public List<DodgeBall> dodgeBallsListTeam1;
public List<DodgeBall> AllBallsList;
// public Dictionary<DodgeBallAgent, DodgeBallPlayer> PlayersDict = new Dictionary<DodgeBallAgent, DodgeBallPlayer>();
private int m_ResetTimer;
public int MaxEnvironmentSteps = 5000;
void FixedUpdate()
{
if (m_ResetTimer > MaxEnvironmentSteps)
{
ResetScene();
}
m_ResetTimer += 1;
}
void Initialize()
DodgeBall db = g.GetComponent<DodgeBall>();
AllBallsList.Add(db);
//Reset Agents
foreach (var item in Team0Players)
{
item.StartingPos = item.Agent.transform.position;
item.StartingRot = item.Agent.transform.rotation;
item.Rb = item.Agent.GetComponent<Rigidbody>();
// item.Col = item.Agent.GetComponent<Collider>();
}
foreach (var item in Team1Players)
{
item.StartingPos = item.Agent.transform.position;
item.StartingRot = item.Agent.transform.rotation;
item.Rb = item.Agent.GetComponent<Rigidbody>();
}
m_Initialized = true;
void ResetScene()
{
m_ResetTimer = 0;
public List<DodgeBallAgent> Team0Players;
public List<DodgeBallAgent> Team1Players;
public List<DodgeBall> dodgeBallsListTeamO;
public List<DodgeBall> dodgeBallsListTeam1;
//Reset Balls
foreach (var item in AllBallsList)
{
item.gameObject.SetActive(true);
item.transform.position = BallSpawnPosition.position + Random.insideUnitSphere * BallSpawnRadius;
}
public Dictionary<DodgeBallAgent, DodgeBallPlayer> PlayersDict = new Dictionary<DodgeBallAgent, DodgeBallPlayer>();
//End Episode
foreach (var item in Team0Players)
{
item.Agent.EndEpisode();
}
foreach (var item in Team1Players)
{
item.Agent.EndEpisode();
}
//Reset Agents
foreach (var item in Team0Players)
{
ResetAgent(item);
}
foreach (var item in Team1Players)
{
ResetAgent(item);
}
}
// Start is called before the first frame update
void Awake()
void ResetAgent(AgentInfo item)
ResetScene();
// var pos = UseRandomAgentPosition ? GetRandomSpawnPos() : item.StartingPos;
// var rot = UseRandomAgentRotation ? GetRandomRot() : item.StartingRot;
item.Agent.transform.SetPositionAndRotation(item.StartingPos, item.StartingRot);
item.Rb.velocity = Vector3.zero;
item.Rb.angularVelocity = Vector3.zero;
item.Agent.gameObject.SetActive(true);
// // Update is called once per frame
// void Update()
// // Start is called before the first frame update
// void Awake()
//
// ResetScene();
// Update is called once per frame
void Update()
{
if (!m_Initialized)
{
Initialize();
}
}
}

2
Project/ProjectSettings/DynamicsManager.asset


m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0
m_ContactsGeneration: 1
m_LayerCollisionMatrix: fffdfffffffdfffffffdfffffffffffffffdfffffffdfffffffffffffffffffffffdffffc8ecffffffdbffffffeffffffff5fffffffbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: fffdfffffffdfffffffdfffffffffffffffdfffffffdfffffffffffffffffffffffdffffc8ecffffffdfffffffeffffffff5fffffffbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_AutoSimulation: 1
m_AutoSyncTransforms: 1
m_ReuseCollisionCallbacks: 1

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存