浏览代码

added scripts

/hh-develop-all-posed-characters
bhh 5 年前
当前提交
35736d30
共有 6 个文件被更改,包括 794 次插入27 次删除
  1. 560
      Project/Assets/ML-Agents/Examples/Snake/Scenes/WormDynamicTarget.unity
  2. 15
      config/trainer_config.yaml
  3. 8
      Project/Assets/ML-Agents/Examples/Snake/Scripts.meta
  4. 225
      Project/Assets/ML-Agents/Examples/Snake/Scripts/WormAgent.cs
  5. 13
      Project/Assets/ML-Agents/Examples/Snake/Scripts/WormAgent.cs.meta

560
Project/Assets/ML-Agents/Examples/Snake/Scenes/WormDynamicTarget.unity


propertyPath: m_Name
value: DynamicPlatform (5)
objectReference: {fileID: 0}
- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4231236244595270, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x
value: 200

- component: {fileID: 446438807}
- component: {fileID: 446438811}
- component: {fileID: 446438810}
- component: {fileID: 446438812}
m_Layer: 0
m_Name: eyeR
m_TagString: Untagged

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 446438806}
m_ConnectedBody: {fileID: 1691972644}
m_ConnectedBody: {fileID: 711885043}
m_ConnectedAnchor: {x: 0.44875965, y: 0.33099186, z: 0.23407243}
m_ConnectedAnchor: {x: 0.4325383, y: 0.59333616, z: -0.59467477}
serializedVersion: 2
m_SecondaryAxis: {x: 0, y: 1, z: 0}
m_XMotion: 0

maximumForce: 3.4028233e+38
m_TargetRotation: {x: 0, y: 0, z: 0, w: 1}
m_TargetAngularVelocity: {x: 0, y: 0, z: 0}
m_RotationDriveMode: 0
m_RotationDriveMode: 1
m_AngularXDrive:
serializedVersion: 3
positionSpring: 0

maximumForce: 3.4028233e+38
m_SlerpDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
positionSpring: 1111
positionDamper: 11
m_ProjectionMode: 0
m_ProjectionMode: 1
m_ProjectionDistance: 0.1
m_ProjectionAngle: 180
m_ConfiguredInWorldSpace: 0

m_EnableCollision: 0
m_EnablePreprocessing: 1
m_EnablePreprocessing: 0
m_MassScale: 1
m_ConnectedMassScale: 1
--- !u!54 &446438811

m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!135 &446438812
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 446438806}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0.00000023841858, z: -0.0000038146973}
--- !u!1 &448952906
GameObject:
m_ObjectHideFlags: 0

- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_Name
value: DynamicPlatform (4)
objectReference: {fileID: 0}
- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4231236244595270, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x

serializedVersion: 6
m_Component:
- component: {fileID: 555429809}
- component: {fileID: 555429812}
- component: {fileID: 555429811}
- component: {fileID: 555429810}
m_Name: SNAKE
m_Name: Worm
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 555429808}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -19.3, y: 0.833, z: 0}
m_LocalPosition: {x: -19.3, y: 0.864, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1157342495}

- {fileID: 691962648}
- {fileID: 1354584760}
- {fileID: 1144668697}
m_Father: {fileID: 0}
m_RootOrder: 12
m_Father: {fileID: 901054388}
m_RootOrder: 4
--- !u!114 &555429810
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 555429808}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1b29724baddfa457da6eeab446fa49ca, type: 3}
m_Name:
m_EditorClassIdentifier:
maxJointSpring: 40000
jointDampen: 3000
maxJointForceLimit: 10000
bodyPartsList: []
--- !u!114 &555429811
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 555429808}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 292fce25fb4b541f4b007a7b92c5923c, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
maxStep: 5000
target: {fileID: 901054389}
ground: {fileID: 901054390}
detectTargets: 1
targetIsStatic: 0
respawnTargetWhenTouched: 1
targetSpawnRadius: 40
bodySegment0: {fileID: 711885042}
bodySegment1: {fileID: 1837513773}
bodySegment2: {fileID: 1426294307}
bodySegment3: {fileID: 1886945678}
rewardMovingTowardsTarget: 1
rewardFacingTarget: 1
rewardUseTimePenalty: 0
--- !u!114 &555429812
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 555429808}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5d1c4e0b1822b495aa52bc52839ecb30, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 1
numStackedVectorObservations: 1
vectorActionSize: 09000000
vectorActionDescriptions: []
vectorActionSpaceType: 1
m_Model: {fileID: 0}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: WormDynamic
TeamId: 0
m_UseChildSensors: 1
--- !u!1 &571548265
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 711885041}
- component: {fileID: 711885040}
- component: {fileID: 711885039}
- component: {fileID: 711885043}
m_Name: BodySeg1
m_Name: BodySeg0
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_Father: {fileID: 555429809}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 89.98, y: 0, z: 0}
--- !u!54 &711885043
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 711885038}
serializedVersion: 2
m_Mass: 3
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &734302698
GameObject:
m_ObjectHideFlags: 0

m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1515093357607024, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4595975114078986, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x
value: 0

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
--- !u!4 &901054388 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4595975114078986, guid: 0058b366f9d6d44a3ba35beb06b0174b,
type: 3}
m_PrefabInstance: {fileID: 901054387}
m_PrefabAsset: {fileID: 0}
--- !u!4 &901054389 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4490950947783742, guid: 0058b366f9d6d44a3ba35beb06b0174b,
type: 3}
m_PrefabInstance: {fileID: 901054387}
m_PrefabAsset: {fileID: 0}
--- !u!4 &901054390 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4684408634944056, guid: 0058b366f9d6d44a3ba35beb06b0174b,
type: 3}
m_PrefabInstance: {fileID: 901054387}
m_PrefabAsset: {fileID: 0}
--- !u!1 &948660337
GameObject:
m_ObjectHideFlags: 0

- {fileID: 746822140}
- {fileID: 893298041}
m_Father: {fileID: 0}
m_RootOrder: 13
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &980673139
GameObject:

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &980673140
Transform:
m_ObjectHideFlags: 0

- {fileID: 404792134}
- {fileID: 571548266}
m_Father: {fileID: 0}
m_RootOrder: 15
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &986425173 stripped
Transform:

- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_Name
value: DynamicPlatform (7)
objectReference: {fileID: 0}
- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4231236244595270, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x

- component: {fileID: 1227308979}
- component: {fileID: 1227308982}
- component: {fileID: 1227308981}
- component: {fileID: 1227308983}
m_Layer: 0
m_Name: eyeL
m_TagString: Untagged

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1227308977}
m_ConnectedBody: {fileID: 1691972644}
m_ConnectedBody: {fileID: 711885043}
m_ConnectedAnchor: {x: -0.5179077, y: 0.20769282, z: 0.1590779}
m_ConnectedAnchor: {x: -0.4991868, y: 0.4998101, z: -0.47165012}
serializedVersion: 2
m_SecondaryAxis: {x: 0, y: 1, z: 0}
m_XMotion: 0

maximumForce: 3.4028233e+38
m_TargetRotation: {x: 0, y: 0, z: 0, w: 1}
m_TargetAngularVelocity: {x: 0, y: 0, z: 0}
m_RotationDriveMode: 0
m_RotationDriveMode: 1
m_AngularXDrive:
serializedVersion: 3
positionSpring: 0

maximumForce: 3.4028233e+38
m_SlerpDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
positionSpring: 1111
positionDamper: 11
m_ProjectionMode: 0
m_ProjectionMode: 1
m_ProjectionDistance: 0.1
m_ProjectionAngle: 180
m_ConfiguredInWorldSpace: 0

m_EnableCollision: 0
m_EnablePreprocessing: 1
m_EnablePreprocessing: 0
m_MassScale: 1
m_ConnectedMassScale: 1
--- !u!54 &1227308982

m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!135 &1227308983
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1227308977}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.49999997
m_Center: {x: 0, y: 0.00000023841858, z: 0}
--- !u!1 &1292371027
GameObject:
m_ObjectHideFlags: 0

- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_Name
value: DynamicPlatform (3)
objectReference: {fileID: 0}
- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4231236244595270, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x

- component: {fileID: 1426294306}
- component: {fileID: 1426294305}
- component: {fileID: 1426294304}
- component: {fileID: 1426294308}
- component: {fileID: 1426294309}
m_Name: BodySeg1 (2)
m_Name: BodySeg2
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_Father: {fileID: 555429809}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 89.98, y: 0, z: 0}
--- !u!54 &1426294308
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1426294303}
serializedVersion: 2
m_Mass: 3
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!153 &1426294309
ConfigurableJoint:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1426294303}
m_ConnectedBody: {fileID: 1837513774}
m_Anchor: {x: 0, y: 0.9999999, z: 0}
m_Axis: {x: 1, y: 0, z: 0}
m_AutoConfigureConnectedAnchor: 1
m_ConnectedAnchor: {x: 0, y: -0.2976965, z: 0.048108652}
serializedVersion: 2
m_SecondaryAxis: {x: 0, y: 0, z: 1}
m_XMotion: 0
m_YMotion: 0
m_ZMotion: 0
m_AngularXMotion: 1
m_AngularYMotion: 1
m_AngularZMotion: 0
m_LinearLimitSpring:
spring: 0
damper: 0
m_LinearLimit:
limit: 0
bounciness: 0
contactDistance: 0
m_AngularXLimitSpring:
spring: 0
damper: 0
m_LowAngularXLimit:
limit: -60
bounciness: 0
contactDistance: 0
m_HighAngularXLimit:
limit: 60
bounciness: 0
contactDistance: 0
m_AngularYZLimitSpring:
spring: 0
damper: 0
m_AngularYLimit:
limit: 60
bounciness: 0
contactDistance: 0
m_AngularZLimit:
limit: 0
bounciness: 0
contactDistance: 0
m_TargetPosition: {x: 0, y: 0, z: 0}
m_TargetVelocity: {x: 0, y: 0, z: 0}
m_XDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_YDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_ZDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_TargetRotation: {x: 0, y: 0, z: 0, w: 1}
m_TargetAngularVelocity: {x: 0, y: 0, z: 0}
m_RotationDriveMode: 1
m_AngularXDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_AngularYZDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_SlerpDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_ProjectionMode: 1
m_ProjectionDistance: 0.1
m_ProjectionAngle: 180
m_ConfiguredInWorldSpace: 0
m_SwapBodies: 0
m_BreakForce: Infinity
m_BreakTorque: Infinity
m_EnableCollision: 0
m_EnablePreprocessing: 0
m_MassScale: 1
m_ConnectedMassScale: 1
--- !u!1 &1450284307
GameObject:
m_ObjectHideFlags: 0

propertyPath: m_Name
value: DynamicPlatform (6)
objectReference: {fileID: 0}
- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4231236244595270, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x
value: 200

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1612466080}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -20.9, y: 0.833, z: 0}
m_LocalPosition: {x: -22.396, y: 0.833, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 357986258}

- {fileID: 1955342833}
- {fileID: 9403375}
m_Father: {fileID: 0}
m_RootOrder: 14
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1612550358
GameObject:

propertyPath: m_Name
value: DynamicPlatform (2)
objectReference: {fileID: 0}
- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4231236244595270, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x
value: 200

- component: {fileID: 1837513772}
- component: {fileID: 1837513771}
- component: {fileID: 1837513770}
- component: {fileID: 1837513774}
- component: {fileID: 1837513775}
m_Name: BodySeg1 (1)
m_Name: BodySeg1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_Father: {fileID: 555429809}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 89.98, y: 0, z: 0}
--- !u!54 &1837513774
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1837513769}
serializedVersion: 2
m_Mass: 3
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!153 &1837513775
ConfigurableJoint:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1837513769}
m_ConnectedBody: {fileID: 711885043}
m_Anchor: {x: 0, y: 0.9999999, z: 0}
m_Axis: {x: 1, y: 0, z: 0}
m_AutoConfigureConnectedAnchor: 1
m_ConnectedAnchor: {x: 0, y: -0.26519454, z: 0.055110097}
serializedVersion: 2
m_SecondaryAxis: {x: 0, y: 0, z: 1}
m_XMotion: 0
m_YMotion: 0
m_ZMotion: 0
m_AngularXMotion: 1
m_AngularYMotion: 1
m_AngularZMotion: 0
m_LinearLimitSpring:
spring: 0
damper: 0
m_LinearLimit:
limit: 0
bounciness: 0
contactDistance: 0
m_AngularXLimitSpring:
spring: 0
damper: 0
m_LowAngularXLimit:
limit: -60
bounciness: 0
contactDistance: 0
m_HighAngularXLimit:
limit: 60
bounciness: 0
contactDistance: 0
m_AngularYZLimitSpring:
spring: 0
damper: 0
m_AngularYLimit:
limit: 60
bounciness: 0
contactDistance: 0
m_AngularZLimit:
limit: 0
bounciness: 0
contactDistance: 0
m_TargetPosition: {x: 0, y: 0, z: 0}
m_TargetVelocity: {x: 0, y: 0, z: 0}
m_XDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_YDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_ZDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_TargetRotation: {x: 0, y: 0, z: 0, w: 1}
m_TargetAngularVelocity: {x: 0, y: 0, z: 0}
m_RotationDriveMode: 1
m_AngularXDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_AngularYZDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_SlerpDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_ProjectionMode: 1
m_ProjectionDistance: 0.1
m_ProjectionAngle: 180
m_ConfiguredInWorldSpace: 0
m_SwapBodies: 0
m_BreakForce: Infinity
m_BreakTorque: Infinity
m_EnableCollision: 0
m_EnablePreprocessing: 0
m_MassScale: 1
m_ConnectedMassScale: 1
--- !u!1 &1839252125
GameObject:
m_ObjectHideFlags: 0

- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_Name
value: DynamicPlatform (1)
objectReference: {fileID: 0}
- target: {fileID: 1226127568872306, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4231236244595270, guid: 0058b366f9d6d44a3ba35beb06b0174b, type: 3}
propertyPath: m_LocalPosition.x

- component: {fileID: 1886945677}
- component: {fileID: 1886945676}
- component: {fileID: 1886945675}
- component: {fileID: 1886945680}
- component: {fileID: 1886945679}
m_Name: BodySeg1 (3)
m_Name: BodySeg3
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_Father: {fileID: 555429809}
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 89.98, y: 0, z: 0}
--- !u!153 &1886945679
ConfigurableJoint:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886945674}
m_ConnectedBody: {fileID: 1426294308}
m_Anchor: {x: 0, y: 0.99999994, z: 0}
m_Axis: {x: 1, y: 0, z: 0}
m_AutoConfigureConnectedAnchor: 1
m_ConnectedAnchor: {x: 0, y: -0.20495974, z: 0.054676183}
serializedVersion: 2
m_SecondaryAxis: {x: 0, y: 0, z: 1}
m_XMotion: 0
m_YMotion: 0
m_ZMotion: 0
m_AngularXMotion: 1
m_AngularYMotion: 1
m_AngularZMotion: 0
m_LinearLimitSpring:
spring: 0
damper: 0
m_LinearLimit:
limit: 0
bounciness: 0
contactDistance: 0
m_AngularXLimitSpring:
spring: 0
damper: 0
m_LowAngularXLimit:
limit: -60
bounciness: 0
contactDistance: 0
m_HighAngularXLimit:
limit: 60
bounciness: 0
contactDistance: 0
m_AngularYZLimitSpring:
spring: 0
damper: 0
m_AngularYLimit:
limit: 60
bounciness: 0
contactDistance: 0
m_AngularZLimit:
limit: 0
bounciness: 0
contactDistance: 0
m_TargetPosition: {x: 0, y: 0, z: 0}
m_TargetVelocity: {x: 0, y: 0, z: 0}
m_XDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_YDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_ZDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_TargetRotation: {x: 0, y: 0, z: 0, w: 1}
m_TargetAngularVelocity: {x: 0, y: 0, z: 0}
m_RotationDriveMode: 1
m_AngularXDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_AngularYZDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_SlerpDrive:
serializedVersion: 3
positionSpring: 0
positionDamper: 0
maximumForce: 3.4028233e+38
m_ProjectionMode: 1
m_ProjectionDistance: 0.1
m_ProjectionAngle: 180
m_ConfiguredInWorldSpace: 0
m_SwapBodies: 0
m_BreakForce: Infinity
m_BreakTorque: Infinity
m_EnableCollision: 0
m_EnablePreprocessing: 0
m_MassScale: 1
m_ConnectedMassScale: 1
--- !u!54 &1886945680
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886945674}
serializedVersion: 2
m_Mass: 3
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &1889786550
GameObject:
m_ObjectHideFlags: 0

15
config/trainer_config.yaml


strength: 1.0
gamma: 0.995
WormDynamic:
normalize: true
num_epoch: 3
time_horizon: 1000
batch_size: 2024
buffer_size: 20240
max_steps: 1e7
summary_freq: 30000
num_layers: 3
hidden_units: 512
reward_signals:
extrinsic:
strength: 1.0
gamma: 0.995
Walker:
normalize: true
num_epoch: 3

8
Project/Assets/ML-Agents/Examples/Snake/Scripts.meta


fileFormatVersion: 2
guid: 8d40fba955e8e4bf58ad001ef520f96c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

225
Project/Assets/ML-Agents/Examples/Snake/Scripts/WormAgent.cs


using UnityEngine;
using MLAgents;
using MLAgentsExamples;
using MLAgents.Sensors;
[RequireComponent(typeof(JointDriveController))] // Required to set joint forces
public class WormAgent : Agent
{
[Header("Target To Walk Towards")]
[Space(10)]
public Transform target;
public Transform ground;
public bool detectTargets;
public bool targetIsStatic;
public bool respawnTargetWhenTouched;
public float targetSpawnRadius;
[Header("Body Parts")] [Space(10)]
public Transform bodySegment0;
public Transform bodySegment1;
public Transform bodySegment2;
public Transform bodySegment3;
[Header("Joint Settings")] [Space(10)]
JointDriveController m_JdController;
Vector3 m_DirToTarget;
float m_MovingTowardsDot;
float m_FacingDot;
[Header("Reward Functions To Use")]
[Space(10)]
public bool rewardMovingTowardsTarget; // Agent should move towards target
public bool rewardFacingTarget; // Agent should face the target
public bool rewardUseTimePenalty; // Hurry up
Quaternion m_LookRotation;
Matrix4x4 m_TargetDirMatrix;
public override void Initialize()
{
m_JdController = GetComponent<JointDriveController>();
m_DirToTarget = target.position - bodySegment0.position;
//Setup each body part
m_JdController.SetupBodyPart(bodySegment0);
m_JdController.SetupBodyPart(bodySegment1);
m_JdController.SetupBodyPart(bodySegment2);
m_JdController.SetupBodyPart(bodySegment3);
}
/// <summary>
/// Add relevant information on each body part to observations.
/// </summary>
public void CollectObservationBodyPart(BodyPart bp, VectorSensor sensor)
{
var rb = bp.rb;
sensor.AddObservation(bp.groundContact.touchingGround ? 1 : 0); // Whether the bp touching the ground
var velocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.velocity);
sensor.AddObservation(velocityRelativeToLookRotationToTarget);
var angularVelocityRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(rb.angularVelocity);
sensor.AddObservation(angularVelocityRelativeToLookRotationToTarget);
if (bp.rb.transform != bodySegment0)
{
var localPosRelToBody = bodySegment0.InverseTransformPoint(rb.position);
sensor.AddObservation(localPosRelToBody);
sensor.AddObservation(bp.currentXNormalizedRot); // Current x rot
sensor.AddObservation(bp.currentYNormalizedRot); // Current y rot
sensor.AddObservation(bp.currentZNormalizedRot); // Current z rot
sensor.AddObservation(bp.currentStrength / m_JdController.maxJointForceLimit);
}
}
public override void CollectObservations(VectorSensor sensor)
{
m_JdController.GetCurrentJointForces();
// Update pos to target
m_DirToTarget = target.position - bodySegment0.position;
m_LookRotation = Quaternion.LookRotation(m_DirToTarget);
m_TargetDirMatrix = Matrix4x4.TRS(Vector3.zero, m_LookRotation, Vector3.one);
RaycastHit hit;
float maxDist = 10;
if (Physics.Raycast(bodySegment0.position, Vector3.down, out hit, maxDist))
{
sensor.AddObservation(hit.distance/maxDist);
}
else
sensor.AddObservation(1);
// Forward & up to help with orientation
var bodyForwardRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(bodySegment0.up);
sensor.AddObservation(bodyForwardRelativeToLookRotationToTarget);
var bodyUpRelativeToLookRotationToTarget = m_TargetDirMatrix.inverse.MultiplyVector(-bodySegment0.forward);
sensor.AddObservation(bodyUpRelativeToLookRotationToTarget);
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
{
CollectObservationBodyPart(bodyPart, sensor);
}
}
/// <summary>
/// Agent touched the target
/// </summary>
public void TouchedTarget()
{
AddReward(1f);
if (respawnTargetWhenTouched)
{
GetRandomTargetPos();
}
}
/// <summary>
/// Moves target to a random position within specified radius.
/// </summary>
public void GetRandomTargetPos()
{
var newTargetPos = Random.insideUnitSphere * targetSpawnRadius;
newTargetPos.y = 5;
target.position = newTargetPos + ground.position;
}
public override void OnActionReceived(float[] vectorAction)
{
// The dictionary with all the body parts in it are in the jdController
var bpDict = m_JdController.bodyPartsDict;
var i = -1;
// Pick a new target joint rotation
bpDict[bodySegment1].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[bodySegment2].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[bodySegment3].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
// Update joint strength
bpDict[bodySegment1].SetJointStrength(vectorAction[++i]);
bpDict[bodySegment2].SetJointStrength(vectorAction[++i]);
bpDict[bodySegment3].SetJointStrength(vectorAction[++i]);
}
void FixedUpdate()
{
if (detectTargets)
{
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
{
if (bodyPart.targetContact && bodyPart.targetContact.touchingTarget)
{
TouchedTarget();
}
}
}
// Set reward for this step according to mixture of the following elements.
if (rewardMovingTowardsTarget)
{
RewardFunctionMovingTowards();
}
if (rewardFacingTarget)
{
RewardFunctionFacingTarget();
}
if (rewardUseTimePenalty)
{
RewardFunctionTimePenalty();
}
}
/// <summary>
/// Reward moving towards target & Penalize moving away from target.
/// </summary>
void RewardFunctionMovingTowards()
{
m_MovingTowardsDot = Vector3.Dot(m_JdController.bodyPartsDict[bodySegment0].rb.velocity, m_DirToTarget.normalized);
AddReward(0.03f * m_MovingTowardsDot);
}
/// <summary>
/// Reward facing target & Penalize facing away from target
/// </summary>
void RewardFunctionFacingTarget()
{
m_FacingDot = Vector3.Dot(m_DirToTarget.normalized, bodySegment0.forward);
AddReward(0.01f * m_FacingDot);
}
/// <summary>
/// Existential penalty for time-contrained tasks.
/// </summary>
void RewardFunctionTimePenalty()
{
AddReward(-0.001f);
}
/// <summary>
/// Loop over body parts and reset them to initial conditions.
/// </summary>
public override void OnEpisodeBegin()
{
if (m_DirToTarget != Vector3.zero)
{
transform.rotation = Quaternion.LookRotation(m_DirToTarget);
}
transform.Rotate(Vector3.up, Random.Range(0.0f, 360.0f));
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
{
bodyPart.Reset(bodyPart);
}
if (!targetIsStatic)
{
GetRandomTargetPos();
}
}
}

13
Project/Assets/ML-Agents/Examples/Snake/Scripts/WormAgent.cs.meta


fileFormatVersion: 2
guid: 292fce25fb4b541f4b007a7b92c5923c
timeCreated: 1525902546
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存