浏览代码

Lots of small fixes, better obs

/develop/battlefoodcollector
Ervin Teng 4 年前
当前提交
aeb0674e
共有 3 个文件被更改,包括 80 次插入56 次删除
  1. 80
      Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/BattleFoodArea.prefab
  2. 12
      Project/Assets/ML-Agents/Examples/FoodCollector/Scenes/BattleFood.unity
  3. 44
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/BattleFoodAgent.cs

80
Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/BattleFoodArea.prefab


- {fileID: 4628244018821590}
- {fileID: 4942777147710886}
m_Father: {fileID: 4137908820211030}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1050257840814314
GameObject:

- component: {fileID: 1395479059576541845}
m_Layer: 0
m_Name: Agent
m_TagString: agent
m_TagString: agent0
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
m_Model: {fileID: 11400000, guid: e7db8916ced8546458dcbe028486a23d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: BattleFoodCollector

m_SensorName: RayPerceptionSensor
m_DetectableTags:
- food
- agent
- agent0
- badFood
- agent1
- frozenAgent
m_RaysPerDirection: 3
m_MaxRayDegrees: 70

- component: {fileID: 596851408027241538}
m_Layer: 0
m_Name: Agent (1)
m_TagString: agent
m_TagString: agent0
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
m_Model: {fileID: 11400000, guid: e7db8916ced8546458dcbe028486a23d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: BattleFoodCollector

m_SensorName: RayPerceptionSensor
m_DetectableTags:
- food
- agent
- agent0
- badFood
- agent1
m_RaysPerDirection: 3
m_RaysPerDirection: 6
m_RayLength: 50
m_RayLength: 100
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291

- component: {fileID: 135878393583328510}
m_Layer: 0
m_Name: Agent (2)
m_TagString: agent
m_TagString: agent0
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
m_Model: {fileID: 11400000, guid: e7db8916ced8546458dcbe028486a23d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: BattleFoodCollector

m_SensorName: RayPerceptionSensor
m_DetectableTags:
- food
- agent
- agent0
- badFood
- agent1
m_RaysPerDirection: 3
m_RaysPerDirection: 6
m_RayLength: 50
m_RayLength: 100
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291

- {fileID: 4582932118026694}
- {fileID: 4599271014211466}
m_Father: {fileID: 4259834826122778}
m_RootOrder: 0
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1618648442086682
GameObject:

- component: {fileID: 5202286717433172320}
m_Layer: 0
m_Name: Agent (4)
m_TagString: agent
m_TagString: agent1
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

m_LocalPosition: {x: -34.2, y: 2, z: -9.559753}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4937005382015814}
- {fileID: 4937005382015814}
m_Father: {fileID: 4688212428263696}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
m_Model: {fileID: 11400000, guid: e7db8916ced8546458dcbe028486a23d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: BattleFoodCollector

m_SensorName: RayPerceptionSensor
m_DetectableTags:
- food
- agent
- agent1
- badFood
- agent0
m_RaysPerDirection: 3
m_RaysPerDirection: 6
m_RayLength: 50
m_RayLength: 100
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291

- component: {fileID: 2100224384926082249}
m_Layer: 0
m_Name: Agent (3)
m_TagString: agent
m_TagString: agent1
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

m_LocalPosition: {x: -34.2, y: 2, z: -9.559753}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4522727213527220}
- {fileID: 4522727213527220}
m_Father: {fileID: 4688212428263696}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
m_Model: {fileID: 11400000, guid: e7db8916ced8546458dcbe028486a23d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: BattleFoodCollector

m_SensorName: RayPerceptionSensor
m_DetectableTags:
- food
- agent
- agent1
- badFood
- agent0
m_RaysPerDirection: 3
m_RaysPerDirection: 6
m_RayLength: 50
m_RayLength: 100
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291

- {fileID: 5144359137687826278}
- {fileID: 8786814285906777632}
m_Father: {fileID: 4137908820211030}
m_RootOrder: 1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &4127280669871741008
MeshFilter:

- component: {fileID: 5958959395267594444}
m_Layer: 0
m_Name: Agent (5)
m_TagString: agent
m_TagString: agent1
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0

VectorActionSize: 03000000030000000300000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
m_Model: {fileID: 11400000, guid: e7db8916ced8546458dcbe028486a23d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: BattleFoodCollector

m_SensorName: RayPerceptionSensor
m_DetectableTags:
- food
- agent
- agent1
- badFood
- agent0
m_RaysPerDirection: 3
m_RaysPerDirection: 6
m_RayLength: 50
m_RayLength: 100
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291

- {fileID: 875547865878971364}
- {fileID: 8034823852301353004}
m_Father: {fileID: 4259834826122778}
m_RootOrder: 1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &4512386870509477965
MeshFilter:

12
Project/Assets/ML-Agents/Examples/FoodCollector/Scenes/BattleFood.unity


propertyPath: m_Name
value: BattleFoodArea (1)
objectReference: {fileID: 0}
- target: {fileID: 1819751139121548, guid: 4a2d272a60b4a453d9ec0f6e5708bd73, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4688212428263696, guid: 4a2d272a60b4a453d9ec0f6e5708bd73, type: 3}
propertyPath: m_LocalPosition.x
value: 0

propertyPath: m_Name
value: BattleFoodArea (2)
objectReference: {fileID: 0}
- target: {fileID: 1819751139121548, guid: 4a2d272a60b4a453d9ec0f6e5708bd73, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4688212428263696, guid: 4a2d272a60b4a453d9ec0f6e5708bd73, type: 3}
propertyPath: m_LocalPosition.x
value: 0

- target: {fileID: 1819751139121548, guid: 4a2d272a60b4a453d9ec0f6e5708bd73, type: 3}
propertyPath: m_Name
value: BattleFoodArea (3)
objectReference: {fileID: 0}
- target: {fileID: 1819751139121548, guid: 4a2d272a60b4a453d9ec0f6e5708bd73, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4688212428263696, guid: 4a2d272a60b4a453d9ec0f6e5708bd73, type: 3}
propertyPath: m_LocalPosition.x

44
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/BattleFoodAgent.cs


EnvironmentParameters m_ResetParams;
string m_TeamTag;
public override void Initialize()
{
m_AgentRb = GetComponent<Rigidbody>();

SetResetParameters();
m_BehaviorParameters = gameObject.GetComponent<BehaviorParameters>();
m_TeamTag = $"agent{m_BehaviorParameters.TeamId}";
gameObject.tag = m_TeamTag;
BattleAgentState playerState = new BattleAgentState
{
teamId = m_BehaviorParameters.TeamId,

RaycastHit hit;
if (Physics.SphereCast(transform.position, 2f, rayDir, out hit, 25f))
{
if (hit.collider.gameObject.CompareTag("agent"))
if (hit.collider.gameObject.tag.StartsWith("agent"))
hit.collider.gameObject.GetComponent<BattleFoodAgent>().Freeze();
// Disable friendly fire
BattleFoodAgent b_agent = hit.collider.gameObject.GetComponent<BattleFoodAgent>();
if (b_agent.m_BehaviorParameters.TeamId != m_BehaviorParameters.TeamId)
{
b_agent.Freeze();
}
}
}
}

void Unfreeze()
{
m_Frozen = false;
gameObject.tag = "agent";
gameObject.tag = m_TeamTag;
gameObject.GetComponentInChildren<Renderer>().material = normalMaterial;
}

void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("food"))
if (!m_Frozen)
Satiate();
collision.gameObject.GetComponent<FoodLogic>().OnEaten();
if (contribute)
if (collision.gameObject.CompareTag("food"))
areaScoring.AddScore(m_BehaviorParameters.TeamId, 1);
Satiate();
collision.gameObject.GetComponent<FoodLogic>().OnEaten();
if (contribute)
{
areaScoring.AddScore(m_BehaviorParameters.TeamId, 1);
}
}
if (collision.gameObject.CompareTag("badFood"))
{
Poison();
collision.gameObject.GetComponent<FoodLogic>().OnEaten();
if (collision.gameObject.CompareTag("badFood"))
{
Poison();
collision.gameObject.GetComponent<FoodLogic>().OnEaten();
if (contribute)
{
areaScoring.AddScore(m_BehaviorParameters.TeamId, -1);
if (contribute)
{
areaScoring.AddScore(m_BehaviorParameters.TeamId, -1);
}
}
}
}

正在加载...
取消
保存