浏览代码

Merge branch 'develop-zombieteammanager-killfirst' into develop-zombieteammanager-disableagent

/develop/zombieteammanager/disableagent
Ervin Teng 3 年前
当前提交
7168a8f2
共有 2 个文件被更改,包括 28 次插入26 次删除
  1. 14
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentCollab.cs
  2. 40
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs

14
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentCollab.cs


ForceMode.VelocityChange);
}
public override void CollectObservations(VectorSensor sensor)
{
if (useVectorObs)
{
sensor.AddObservation(StepCount / (float)MaxStep);
}
}
// public override void CollectObservations(VectorSensor sensor)
// {
// if (useVectorObs)
// {
// sensor.AddObservation(StepCount / (float)MaxStep);
// }
// }
/// <summary>
/// Called every step of the engine. Here the agent takes an action.

40
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs


// Unfreeze block's motion when zombies are killed
item.Rb.constraints &= RigidbodyConstraints.FreezePositionX;
item.Rb.constraints &= RigidbodyConstraints.FreezePositionZ;
item.Rb.constraints &= RigidbodyConstraints.FreezeRotationY;
}
}
}

/// Use the ground's bounds to pick a random spawn position.
/// </summary>
public Vector3 GetRandomSpawnPos()
public Vector3 GetRandomSpawnPos(float boundsX = 2.5f, float boundsZ = 2.5f)
{
var foundNewSpawnLocation = false;
var randomSpawnPos = Vector3.zero;

var randomPosZ = Random.Range(-areaBounds.extents.z * m_PushBlockSettings.spawnAreaMarginMultiplier,
areaBounds.extents.z * m_PushBlockSettings.spawnAreaMarginMultiplier);
randomSpawnPos = ground.transform.position + new Vector3(randomPosX, 1f, randomPosZ);
if (Physics.CheckBox(randomSpawnPos, new Vector3(2.5f, 0.01f, 2.5f)) == false)
if (Physics.CheckBox(randomSpawnPos, new Vector3(boundsX, 0.01f, boundsZ)) == false)
{
foundNewSpawnLocation = true;
}

void ResetBlock(BlockInfo block)
{
// Get a random position for the block.
block.T.position = GetRandomSpawnPos();
block.T.position = GetRandomSpawnPos(3f, 3f);
// Reset block velocity back to zero.
block.Rb.velocity = Vector3.zero;

}
item.Agent.EndEpisode();
}
//Reset Blocks
foreach (var item in BlocksList)
{
var pos = UseRandomBlockPosition ? GetRandomSpawnPos(2.5f, 2.5f) : item.StartingPos;
var rot = UseRandomBlockRotation ? GetRandomRot() : item.StartingRot;
item.T.transform.SetPositionAndRotation(pos, rot);
item.Rb.velocity = Vector3.zero;
item.Rb.angularVelocity = Vector3.zero;
item.T.gameObject.SetActive(true);
// Freeze block's motion until zombies are killed
item.Rb.constraints |= RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
item.Rb.constraints |= RigidbodyConstraints.FreezeRotationY;
}
//Reset Agents
foreach (var item in AgentsList)
{

item.Rb.constraints &= ~RigidbodyConstraints.FreezePositionY;
}
//Reset Blocks
foreach (var item in BlocksList)
{
var pos = UseRandomBlockPosition ? GetRandomSpawnPos() : item.StartingPos;
var rot = UseRandomBlockRotation ? GetRandomRot() : item.StartingRot;
item.T.transform.SetPositionAndRotation(pos, rot);
item.Rb.velocity = Vector3.zero;
item.Rb.angularVelocity = Vector3.zero;
item.T.gameObject.SetActive(true);
// Freeze block's motion until zombies are killed
item.Rb.constraints |= RigidbodyConstraints.FreezePositionX;
item.Rb.constraints |= RigidbodyConstraints.FreezePositionZ;
}
//End Episode
foreach (var item in ZombiesList)
{

正在加载...
取消
保存