浏览代码

Clean up Area environment code

/tag-0.2.0
Arthur Juliani 7 年前
当前提交
fde0a417
共有 8 个文件被更改,包括 1262 次插入666 次删除
  1. 101
      unity-environment/Assets/ML-Agents/Examples/Area/Prefabs/PushArea.prefab
  2. 109
      unity-environment/Assets/ML-Agents/Examples/Area/Prefabs/WallArea.prefab
  3. 818
      unity-environment/Assets/ML-Agents/Examples/Area/Push.unity
  4. 75
      unity-environment/Assets/ML-Agents/Examples/Area/Scripts/AreaAgent.cs
  5. 37
      unity-environment/Assets/ML-Agents/Examples/Area/Scripts/Push/PushAgent.cs
  6. 2
      unity-environment/Assets/ML-Agents/Examples/Area/Scripts/Push/PushArea.cs
  7. 38
      unity-environment/Assets/ML-Agents/Examples/Area/Scripts/Wall/WallAgent.cs
  8. 748
      unity-environment/Assets/ML-Agents/Examples/Area/Wall.unity

101
unity-environment/Assets/ML-Agents/Examples/Area/Prefabs/PushArea.prefab


m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1433578436929790
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4379575143948170}
- component: {fileID: 20019178239241812}
m_Layer: 0
m_Name: AgentCam
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 1
m_IsActive: 0
--- !u!1 &1493483966197088
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 65667507680723650}
- component: {fileID: 23372235118339718}
- component: {fileID: 54979596905483200}
- component: {fileID: 114772202904937800}
- component: {fileID: 114371909629876940}
m_Layer: 0
m_Name: Agent

m_Father: {fileID: 4797372522419518}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4379575143948170
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1433578436929790}
m_LocalRotation: {x: 0.38268343, y: -0, z: -0, w: 0.92387956}
m_LocalPosition: {x: 0, y: 9, z: -7}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4777271908265906}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0}
--- !u!4 &4466531474194842
Transform:
m_ObjectHideFlags: 1

m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -9}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4379575143948170}
m_Children: []
m_Father: {fileID: 4797372522419518}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &20019178239241812
Camera:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1433578436929790}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!23 &23361251118430556
MeshRenderer:
m_ObjectHideFlags: 1

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

reward: 0
done: 0
value: 0
CummulativeReward: 0
CumulativeReward: 0
stepCounter: 0
agentStoredAction: []
memory: []

block: {fileID: 1493483966197088}
--- !u!114 &114772202904937800
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1893190605547158}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e040eaa8759024abbbb14994dc4c55ee, type: 3}
m_Name:
m_EditorClassIdentifier:
fixedPosition: 0
verticalOffset: 2
DisplayBrainName: 0
DisplayBrainType: 0
DisplayFrameCount: 0
DisplayCurrentReward: 0
DisplayMaxReward: 0
DisplayState: 0
DisplayAction: 0
--- !u!114 &114824876818673492
MonoBehaviour:
m_ObjectHideFlags: 1

109
unity-environment/Assets/ML-Agents/Examples/Area/Prefabs/WallArea.prefab


m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1353235869903194
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4812106314987956}
- component: {fileID: 20444604189257518}
m_Layer: 0
m_Name: AgentCam
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!1 &1506931635139370
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 23613202787206598}
- component: {fileID: 54973601004961626}
- component: {fileID: 114200736018184412}
- component: {fileID: 114280768661186092}
m_Layer: 0
m_Name: Agent
m_TagString: Untagged

m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -9}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4812106314987956}
m_Children: []
m_Father: {fileID: 4601298475788644}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1718829686919056}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -15, y: 0, z: 0}
m_LocalPosition: {x: -10, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4182184265281318}

m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1960504220667788}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.5, z: 0}
m_LocalPosition: {x: 0, y: 0.25, z: 0}
m_LocalScale: {x: 2.2, y: 1.1, z: 2.2}
m_Children:
- {fileID: 4743003964451344}

m_Father: {fileID: 4291466584800356}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &4812106314987956
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1353235869903194}
m_LocalRotation: {x: 0.38268343, y: -0, z: -0, w: 0.92387956}
m_LocalPosition: {x: 0, y: 9, z: -7}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4182184265281318}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0}
--- !u!4 &4826682057551308
Transform:
m_ObjectHideFlags: 1

m_Father: {fileID: 4601298475788644}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &20444604189257518
Camera:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1353235869903194}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!23 &23415401456686744
MeshRenderer:
m_ObjectHideFlags: 1

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5

reward: 0
done: 0
value: 0
CummulativeReward: 0
CumulativeReward: 0
area: {fileID: 1718829686919056}
area: {fileID: 1718829686919056}
wall: {fileID: 1506931635139370}
--- !u!114 &114215545026793406
MonoBehaviour:

academy: {fileID: 0}
block: {fileID: 1312874949203312}
goalHolder: {fileID: 1960504220667788}
--- !u!114 &114280768661186092
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1986507356043702}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e040eaa8759024abbbb14994dc4c55ee, type: 3}
m_Name:
m_EditorClassIdentifier:
fixedPosition: 0
verticalOffset: 2
DisplayBrainName: 0
DisplayBrainType: 0
DisplayFrameCount: 0
DisplayCurrentReward: 0
DisplayMaxReward: 0
DisplayState: 0
DisplayAction: 0

818
unity-environment/Assets/ML-Agents/Examples/Area/Push.unity
文件差异内容过多而无法显示
查看文件

75
unity-environment/Assets/ML-Agents/Examples/Area/Scripts/AreaAgent.cs


state.Add(velocity.x);
state.Add(velocity.y);
state.Add(velocity.z);
return state;
}
public void MoveAgent(int movement) {
float directionX = 0;
float directionZ = 0;
float directionY = 0;
if (movement == 1) { directionX = -1; }
if (movement == 2) { directionX = 1; }
if (movement == 3) { directionZ = -1; }
if (movement == 4) { directionZ = 1; }
if (movement == 5 && GetComponent<Rigidbody>().velocity.y <= 0) { directionY = 1; }
return state;
}
float edge = 0.499f;
float rayDepth = 0.51f;
Vector3 fwd = transform.TransformDirection(Vector3.down);
if (!Physics.Raycast(transform.position, fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(edge, 0f, 0f), fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(-edge, 0f, 0f), fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, edge), fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, -edge), fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(edge, 0f, edge), fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(-edge, 0f, edge), fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(edge, 0f, -edge), fwd, rayDepth) &&
!Physics.Raycast(transform.position + new Vector3(-edge, 0f, -edge), fwd, rayDepth))
{
directionY = 0f;
directionX = directionX / 5f;
directionZ = directionZ / 5f;
}
gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(directionX * 40f, directionY * 300f, directionZ * 40f));
if (GetComponent<Rigidbody>().velocity.sqrMagnitude > 25f)
{
GetComponent<Rigidbody>().velocity *= 0.95f;
}
}
float movement = act[0];
float directionX = 0;
float directionZ = 0;
float directionY = 0;
if (movement == 1) { directionX = -1; }
if (movement == 2) { directionX = 1; }
if (movement == 3) { directionZ = -1; }
if (movement == 4) { directionZ = 1; }
if (movement == 5 && GetComponent<Rigidbody>().velocity.y <= 0) { directionY = 1; }
int movement = Mathf.FloorToInt(act[0]);
MoveAgent(movement);
Vector3 fwd = transform.TransformDirection(Vector3.down);
if (!Physics.Raycast(transform.position, fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, 0f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, 0f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, -0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, -0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, -0.499f), fwd, 0.51f))
{
directionY = 0f;
directionX = directionX / 5f;
directionZ = directionZ / 5f;
}
gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(directionX * 40f, directionY * 300f, directionZ * 40f));
if (GetComponent<Rigidbody>().velocity.sqrMagnitude > 25f)
{
GetComponent<Rigidbody>().velocity *= 0.95f;
}
if (gameObject.transform.position.y < 0.0f || Mathf.Abs(gameObject.transform.position.x - area.transform.position.x) > 8f || Mathf.Abs(gameObject.transform.position.z + 5 - area.transform.position.z) > 8)
if (gameObject.transform.position.y < 0.0f || Mathf.Abs(gameObject.transform.position.x - area.transform.position.x) > 8f ||
Mathf.Abs(gameObject.transform.position.z + 5 - area.transform.position.z) > 8)
{
done = true;
reward = -1f;

37
unity-environment/Assets/ML-Agents/Examples/Area/Scripts/Push/PushAgent.cs


public override void AgentStep(float[] act)
{
reward = -0.01f;
float movement = act[0];
float directionX = 0;
float directionZ = 0;
float directionY = 0;
if (movement == 1) { directionX = -1; }
if (movement == 2) { directionX = 1; }
if (movement == 3) { directionZ = -1; }
if (movement == 4) { directionZ = 1; }
if (movement == 5 && GetComponent<Rigidbody>().velocity.y <= 0) { directionY = 1; }
int movement = Mathf.FloorToInt(act[0]);
MoveAgent(movement);
Vector3 fwd = transform.TransformDirection(Vector3.down);
if (!Physics.Raycast(transform.position, fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, 0f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, 0f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, -0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, -0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, -0.499f), fwd, 0.51f))
{
directionY = 0f;
directionX = directionX / 5f;
directionZ = directionZ / 5f;
}
gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(directionX * 40f, directionY * 300f, directionZ * 40f));
if (GetComponent<Rigidbody>().velocity.sqrMagnitude > 25f)
{
GetComponent<Rigidbody>().velocity *= 0.95f;
}
if (gameObject.transform.position.y < 0.0f || Mathf.Abs(gameObject.transform.position.x - area.transform.position.x) > 8f || Mathf.Abs(gameObject.transform.position.z + 5 - area.transform.position.z) > 8)
if (gameObject.transform.position.y < 0.0f || Mathf.Abs(gameObject.transform.position.x - area.transform.position.x) > 8f ||
Mathf.Abs(gameObject.transform.position.z + 5 - area.transform.position.z) > 8)
{
done = true;
reward = -1f;

2
unity-environment/Assets/ML-Agents/Examples/Area/Scripts/Push/PushArea.cs


goalHolder.transform.position = new Vector3(Random.Range(-3.5f, 3.5f), -0.1f, Random.Range(0f, -3f)) + gameObject.transform.position;
float size = academy.GetComponent<PushAcademy>().objectSize;
size = Random.Range(size * 0.9f, size * 1.1f);
block.transform.localScale = new Vector3(size, 1f, size);
goalHolder.transform.localScale = new Vector3(size + 1f, 1f, size + 1f);
}

38
unity-environment/Assets/ML-Agents/Examples/Area/Scripts/Wall/WallAgent.cs


public override void AgentStep(float[] act)
{
reward = -0.01f;
float movement = act[0];
float directionX = 0;
float directionZ = 0;
float directionY = 0;
if (movement == 1) { directionX = -1; }
if (movement == 2) { directionX = 1; }
if (movement == 3) { directionZ = -1; }
if (movement == 4) { directionZ = 1; }
if (movement == 5 && GetComponent<Rigidbody>().velocity.y <= 0) { directionY = 1; }
Vector3 fwd = transform.TransformDirection(Vector3.down);
if (!Physics.Raycast(transform.position, fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, 0f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, 0f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.0f, 0f, -0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, 0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(0.499f, 0f, -0.499f), fwd, 0.51f) &&
!Physics.Raycast(transform.position + new Vector3(-0.499f, 0f, -0.499f), fwd, 0.51f))
{
directionY = 0f;
directionX = directionX / 5f;
directionZ = directionZ / 5f;
}
int movement = Mathf.FloorToInt(act[0]);
MoveAgent(movement);
gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(directionX * 40f, directionY * 300f, directionZ * 40f));
if (GetComponent<Rigidbody>().velocity.sqrMagnitude > 25f)
{
GetComponent<Rigidbody>().velocity *= 0.95f;
}
if (gameObject.transform.position.y < 0.0f || Mathf.Abs(gameObject.transform.position.x - area.transform.position.x) > 8f || Mathf.Abs(gameObject.transform.position.z + 5 - area.transform.position.z) > 8)
if (gameObject.transform.position.y < 0.0f ||
Mathf.Abs(gameObject.transform.position.x - area.transform.position.x) > 8f ||
Mathf.Abs(gameObject.transform.position.z + 5 - area.transform.position.z) > 8)
{
done = true;
reward = -1f;

748
unity-environment/Assets/ML-Agents/Examples/Area/Wall.unity
文件差异内容过多而无法显示
查看文件

正在加载...
取消
保存