浏览代码

Stop block from spawning in goal

/develop/zombieteammanager/killfirst
Ervin Teng 4 年前
当前提交
ac2eb777
共有 2 个文件被更改,包括 36 次插入46 次删除
  1. 44
      Project/Assets/ML-Agents/Examples/PushBlock/Scenes/2ZombieVs3AgentsPushBlock.unity
  2. 38
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs

44
Project/Assets/ML-Agents/Examples/PushBlock/Scenes/2ZombieVs3AgentsPushBlock.unity


m_Script: {fileID: 11500000, guid: 7df9fa4d08b7d4d198d5165b07ddd47e, type: 3}
m_Name:
m_EditorClassIdentifier:
MaxEnvironmentSteps: 25000
MaxEnvironmentSteps: 500
areaBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}

Rb: {fileID: 0}
UseRandomAgentRotation: 1
UseRandomAgentPosition: 1
UseRandomBlockRotation: 1
UseRandomBlockRotation: 0
UseRandomBlockPosition: 1
--- !u!4 &35422107
Transform:

m_GameObject: {fileID: 180376172}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2.8199997, y: 1, z: -1.43}
m_LocalScale: {x: 4, y: 0.75, z: 4}
m_LocalScale: {x: 3.5, y: 1.5, z: 3.5}
m_Children: []
m_Father: {fileID: 35422107}
m_RootOrder: 6

VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 2c785861dab4f42309917b4d04e2c8e7, type: 3}
m_Model: {fileID: 11400000, guid: e0908206441554d6b8031e20e7bba934, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: PushBlock

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!1 &263418408
GameObject:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &265967282
MonoBehaviour:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &344861064
MonoBehaviour:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &557898664
MonoBehaviour:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &607937517
MonoBehaviour:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &742698648
MonoBehaviour:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &816508913
MonoBehaviour:

m_GameObject: {fileID: 997359139}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2.8199997, y: 1, z: -1.43}
m_LocalScale: {x: 4, y: 0.75, z: 4}
m_LocalScale: {x: 3.5, y: 1.5, z: 3.5}
m_Children: []
m_Father: {fileID: 1056693890}
m_RootOrder: 6

m_Script: {fileID: 11500000, guid: 7df9fa4d08b7d4d198d5165b07ddd47e, type: 3}
m_Name:
m_EditorClassIdentifier:
MaxEnvironmentSteps: 25000
MaxEnvironmentSteps: 500
areaBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}

Rb: {fileID: 0}
UseRandomAgentRotation: 1
UseRandomAgentPosition: 1
UseRandomBlockRotation: 1
UseRandomBlockRotation: 0
UseRandomBlockPosition: 1
--- !u!4 &1056693890
Transform:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &1504325949
MonoBehaviour:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &1614947134
MonoBehaviour:

m_GameObject: {fileID: 1906676962}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2.8199997, y: 1, z: -1.43}
m_LocalScale: {x: 4, y: 0.75, z: 4}
m_LocalScale: {x: 3.5, y: 1.5, z: 3.5}
m_Children: []
m_Father: {fileID: 2124347356}
m_RootOrder: 6

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &1914183271
MonoBehaviour:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 1
--- !u!114 &2029153700
MonoBehaviour:

VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 2c785861dab4f42309917b4d04e2c8e7, type: 3}
m_Model: {fileID: 11400000, guid: e0908206441554d6b8031e20e7bba934, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: PushBlock

m_Script: {fileID: 11500000, guid: 7df9fa4d08b7d4d198d5165b07ddd47e, type: 3}
m_Name:
m_EditorClassIdentifier:
MaxEnvironmentSteps: 25000
MaxEnvironmentSteps: 500
areaBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}

Rb: {fileID: 0}
UseRandomAgentRotation: 1
UseRandomAgentPosition: 1
UseRandomBlockRotation: 1
UseRandomBlockRotation: 0
UseRandomBlockPosition: 1
--- !u!4 &2124347356
Transform:

m_Script: {fileID: 11500000, guid: 7df9fa4d08b7d4d198d5165b07ddd47e, type: 3}
m_Name:
m_EditorClassIdentifier:
MaxEnvironmentSteps: 25000
MaxEnvironmentSteps: 500
areaBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}

StartingRot: {x: 0, y: 0, z: 0, w: 0}
Rb: {fileID: 0}
UseRandomAgentRotation: 1
UseRandomAgentPosition: 0
UseRandomBlockRotation: 1
UseRandomAgentPosition: 1
UseRandomBlockRotation: 0
UseRandomBlockPosition: 1
--- !u!1 &1257456948449766
GameObject:

maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
frozen: 0
useVectorObs: 0
--- !u!1 &1500989827241484
GameObject:

VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 2c785861dab4f42309917b4d04e2c8e7, type: 3}
m_Model: {fileID: 11400000, guid: e0908206441554d6b8031e20e7bba934, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: PushBlock

m_GameObject: {fileID: 8120829477783372687}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2.8199997, y: 1, z: -1.43}
m_LocalScale: {x: 4, y: 0.75, z: 4}
m_LocalScale: {x: 3.5, y: 1.5, z: 3.5}
m_Children: []
m_Father: {fileID: 4006991767121726}
m_RootOrder: 6

38
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 Agents
foreach (var item in AgentsList)
{
var pos = UseRandomAgentPosition ? GetRandomSpawnPos() : item.StartingPos;
var rot = UseRandomAgentRotation ? GetRandomRot() : item.StartingRot;
item.Agent.transform.SetPositionAndRotation(pos, rot);
item.Rb.velocity = Vector3.zero;
item.Rb.angularVelocity = Vector3.zero;
item.Agent.gameObject.SetActive(true);
}
var pos = UseRandomBlockPosition ? GetRandomSpawnPos() : item.StartingPos;
var pos = UseRandomBlockPosition ? GetRandomSpawnPos(3f, 3f) : item.StartingPos;
var rot = UseRandomBlockRotation ? GetRandomRot() : item.StartingRot;
item.T.transform.SetPositionAndRotation(pos, rot);

// Freeze block's motion until zombies are killed
item.Rb.constraints |= RigidbodyConstraints.FreezePositionX;
item.Rb.constraints |= RigidbodyConstraints.FreezePositionZ;
item.Rb.constraints |= RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
item.Rb.constraints |= RigidbodyConstraints.FreezeRotationY;
}
//Reset Agents
foreach (var item in AgentsList)
{
var pos = UseRandomAgentPosition ? GetRandomSpawnPos() : item.StartingPos;
var rot = UseRandomAgentRotation ? GetRandomRot() : item.StartingRot;
item.Agent.transform.SetPositionAndRotation(pos, rot);
item.Rb.velocity = Vector3.zero;
item.Rb.angularVelocity = Vector3.zero;
item.Agent.gameObject.SetActive(true);
//End Episode
foreach (var item in ZombiesList)
{

正在加载...
取消
保存