浏览代码

continuous, crawler integrated, new cube

/exp-continuous-div
Andrew Cohen 4 年前
当前提交
d813bfd5
共有 13 个文件被更改,包括 3140 次插入29 次删除
  1. 69
      Project/Assets/ML-Agents/Examples/Crawler/Prefabs/Platform.prefab
  2. 12
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
  3. 3
      config/sac/Crawler.yaml
  4. 50
      ml-agents/mlagents/trainers/sac/optimizer_torch.py
  5. 762
      Project/Assets/ML-Agents/Examples/Crawler/Prefabs/CubePlatform.prefab
  6. 7
      Project/Assets/ML-Agents/Examples/Crawler/Prefabs/CubePlatform.prefab.meta
  7. 1001
      Project/Assets/ML-Agents/Examples/Crawler/Scenes/CubeMove.unity
  8. 7
      Project/Assets/ML-Agents/Examples/Crawler/Scenes/CubeMove.unity.meta
  9. 204
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CubeAgent.cs
  10. 11
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CubeAgent.cs.meta
  11. 1001
      Project/Assets/ML-Agents/Examples/Crawler/TFModels/CubeDiv-984000.onnx
  12. 14
      Project/Assets/ML-Agents/Examples/Crawler/TFModels/CubeDiv-984000.onnx.meta
  13. 28
      config/sac/Cube.yaml

69
Project/Assets/ML-Agents/Examples/Crawler/Prefabs/Platform.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &8256113998235913655
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3421283062001101782}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 38b7cc1f5819445aa85e9a9b054552dc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SensorName: Diversity
m_ObservationSize: 8
m_ObservationType: 1
--- !u!1 &6813981368972186340
GameObject:
m_ObjectHideFlags: 0

m_Component:
- component: {fileID: 6810587057221831324}
m_Layer: 0
m_Name: DynamicPlatform
m_Name: Platform
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_Modification:
m_TransformParent: {fileID: 6810587057221831324}
m_Modifications:
- target: {fileID: 4845971001588102144, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: groundContactPenalty
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4845971001715176648, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_Model
value:
objectReference: {fileID: 5022602860645237092, guid: 2cc639f58d6ec4ec1a43e25f57deead9,
type: 3}
- target: {fileID: 4845971001715176649, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_DiversitySetting
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}

type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0456c89e8c9c243d595b039fe7aa0bf9, type: 3}
--- !u!1 &3421283062001101782 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 4845971001715176661, guid: 0456c89e8c9c243d595b039fe7aa0bf9,
type: 3}
m_PrefabInstance: {fileID: 7798701981554532099}
m_PrefabAsset: {fileID: 0}
--- !u!4 &3421283062001101768 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4845971001715176651, guid: 0456c89e8c9c243d595b039fe7aa0bf9,

12
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs


m_JdController.SetupBodyPart(leg2Lower);
m_JdController.SetupBodyPart(leg3Upper);
m_JdController.SetupBodyPart(leg3Lower);
GetComponent<VectorSensorComponent>().CreateSensors();
m_DiversitySettingSensor = GetComponent<VectorSensorComponent>();
VectorSensorComponent m_DiversitySettingSensor;
public int m_DiversitySetting = 0;
/// <summary>
/// Spawns a target prefab at pos

//Set our goal walking speed
TargetWalkingSpeed = Random.Range(0.1f, m_maxWalkingSpeed);
m_DiversitySetting = Random.Range(0, 8);
}
/// <summary>

/// </summary>
public override void CollectObservations(VectorSensor sensor)
{
m_DiversitySettingSensor.GetSensor().Reset();
m_DiversitySettingSensor.GetSensor().AddOneHotObservation(m_DiversitySetting, 8);
var cubeForward = m_OrientationCube.transform.forward;
//velocity we want to match

//This reward will approach 1 if it faces the target direction perfectly and approach zero as it deviates
var lookAtTargetReward = (Vector3.Dot(cubeForward, body.forward) + 1) * .5F;
AddReward(matchSpeedReward * lookAtTargetReward);
AddReward(2f + matchSpeedReward * lookAtTargetReward);
}
/// <summary>

3
config/sac/Crawler.yaml


hidden_units: 512
num_layers: 3
vis_encode_type: simple
goal_conditioning_type: none
reward_signals:
extrinsic:
gamma: 0.995

time_horizon: 1000
summary_freq: 30000
summary_freq: 3000

50
ml-agents/mlagents/trainers/sac/optimizer_torch.py


from contextlib import ExitStack
from mlagents.trainers.trajectory import ObsUtil
from mlagents.trainers.torch.distributions import GaussianDistribution
EPSILON = 1e-6 # Small value to avoid divide by zero
logger = get_logger(__name__)

class DiverseNetwork(torch.nn.Module):
EPSILON = 1e-10
STRENGTH = 0.1
STRENGTH = 1.0
self._use_continuous = True
state_encoder_settings = settings
if state_encoder_settings.memory is not None:
state_encoder_settings.memory = None

)
else:
self._encoder = NetworkBody(new_spec, state_encoder_settings)
self._last_layer = torch.nn.Linear(
state_encoder_settings.hidden_units, self.diverse_size
)
if self._use_continuous:
self._last_layer = GaussianDistribution(state_encoder_settings.hidden_units, self.diverse_size)
else:
self._last_layer = torch.nn.Linear(
state_encoder_settings.hidden_units, self.diverse_size
)
self._diverse_index = -1
self._max_index = len(specs.observation_specs)
for i, spec in enumerate(specs.observation_specs):

def predict(self, obs_input, action_input, detach_action=False) -> torch.Tensor:
def _predict(self, obs_input, action_input, detach_action=False) -> torch.Tensor:
# Convert to tensors
tensor_obs = [
obs

hidden, _ = self._encoder.forward(tensor_obs)
# add a VAE (like in VAIL ?)
prediction = torch.softmax(self._last_layer(hidden), dim=1)
if self._use_continuous:
prediction = self._last_layer(hidden)
else:
prediction = torch.softmax(self._last_layer(hidden), dim=1)
return prediction
def copy_normalization(self, thing):

truth = obs_input[self._diverse_index]
prediction = self.predict(obs_input, action_input, detach_action)
rewards = torch.log(torch.sum((prediction * truth), dim=1) + self.EPSILON)
prediction = self._predict(obs_input, action_input, detach_action)
if self._use_continuous:
rewards = torch.sum(prediction.log_prob(truth), dim=1)
else:
rewards = torch.log(torch.sum((prediction * truth), dim=1) + self.EPSILON)
return rewards
def loss(self, obs_input, action_input, masks, detach_action=True) -> torch.Tensor:

with torch.no_grad():
v_backup = (
min_policy_qs[name]
- torch.sum(_cont_ent_coef * log_probs.continuous_tensor, dim=1)
- _cont_ent_coef * torch.sum(log_probs.continuous_tensor, dim=1)
+ self._mede_network.STRENGTH
* self._mede_network.rewards(obs, act)
)

value_losses.append(value_loss)
else:
print("MEDE not being added to V")
disc_log_probs = log_probs.all_discrete_tensor
branched_per_action_ent = ModelUtils.break_into_branches(
disc_log_probs * disc_log_probs.exp(),

all_mean_q1 = mean_q1
if self._action_spec.continuous_size > 0:
cont_log_probs = log_probs.continuous_tensor
batch_policy_loss += torch.mean(
_cont_ent_coef * cont_log_probs - all_mean_q1.unsqueeze(1), dim=1
) - self._mede_network.STRENGTH * self._mede_network.rewards(obs, act)
#batch_policy_loss += torch.mean(
batch_policy_loss += _cont_ent_coef * torch.sum(cont_log_probs, dim=1) - all_mean_q1 - self._mede_network.STRENGTH * self._mede_network.rewards(obs, act)
policy_loss = ModelUtils.masked_mean(batch_policy_loss, loss_masks)
return policy_loss

if self._action_spec.continuous_size > 0:
with torch.no_grad():
cont_log_probs = log_probs.continuous_tensor
target_current_diff = torch.sum(
cont_log_probs + self.target_entropy.continuous, dim=1
)
#target_current_diff = torch.sum(
# cont_log_probs + self.target_entropy.continuous, dim=1
#)
target_current_diff = torch.sum(cont_log_probs, dim=1) + self.target_entropy.continuous
# We update all the _cont_ent_coef as one block
entropy_loss += -1 * ModelUtils.masked_mean(
_cont_ent_coef * target_current_diff, loss_masks

mede_loss.backward()
self._mede_optimizer.step()
with torch.no_grad():
mede_rewards = torch.mean(self._mede_network.rewards(current_obs, sampled_actions)).item()
# Update target network
ModelUtils.soft_update(self._critic, self.target_network, self.tau)
update_stats = {

).item(),
"Policy/Learning Rate": decay_lr,
"Policy/MEDE Loss": mede_loss.item(),
"Policy/MEDE Rewards": mede_rewards,
}
return update_stats

762
Project/Assets/ML-Agents/Examples/Crawler/Prefabs/CubePlatform.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!54 &99726461408834740
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 84
m_CollisionDetection: 2
--- !u!65 &2072189748365361906
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &1931639611344426838
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c38fe3d08399d4266b7feff82f7a46e7, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 5000
agentRb: {fileID: 0}
initialPos: {x: 0, y: 0, z: 0}
area: {fileID: 6813981368972186340}
TargetPrefab: {fileID: 3839136118347789758, guid: 46734abd0de454192b407379c6a4ab8d,
type: 3}
useContinuous: 1
m_DiversitySetting: 0
div1: 0
div2: 0
div3: 0
div4: 0
--- !u!114 &3714599535519474064
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 38b7cc1f5819445aa85e9a9b054552dc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SensorName: Diversity
m_ObservationSize: 4
m_ObservationType: 1
--- !u!114 &3964008451074753306
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bb6b867a41448888c1cd4f99643ad71, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SensorName: RayPerceptionSensor
m_DetectableTags:
- target
m_RaysPerDirection: 10
m_MaxRayDegrees: 180
m_SphereCastRadius: 1
m_RayLength: 100
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291
m_ObservationStacks: 3
rayHitColor: {r: 1, g: 0, b: 0, a: 1}
rayMissColor: {r: 1, g: 1, b: 1, a: 1}
m_StartVerticalOffset: 0
m_EndVerticalOffset: 0
--- !u!114 &4782055922627238149
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3a5c9d521e5ef4759a8246a07d52221e, type: 3}
m_Name:
m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
--- !u!114 &4843516198797714366
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5086c435d3e8b44ffa8262a5c124661f, type: 3}
m_Name:
m_EditorClassIdentifier:
touchingTarget: 0
--- !u!114 &4865291478266050265
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1544170231188215593}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5d1c4e0b1822b495aa52bc52839ecb30, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes:
VectorActionSize: 03000000
VectorActionDescriptions: []
VectorActionSpaceType: 1
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 5022602860645237092, guid: 4ccca19b2537343baa8dc44f367b720f, type: 3}
m_InferenceDevice: 2
m_BehaviorType: 0
m_BehaviorName: CubeDiv
TeamId: 0
m_UseChildSensors: 1
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!1 &6813981368972186340
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6810587057221831324}
m_Layer: 0
m_Name: CubePlatform
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6810587057221831324
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6813981368972186340}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 6810593986226363672}
- {fileID: 6810815557394078638}
- {fileID: 1547398244452357329}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &6813985912316207378
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6810928998577562200}
- component: {fileID: 6837517112052221168}
- component: {fileID: 6829370902646183816}
- component: {fileID: 6805880649474809276}
m_Layer: 0
m_Name: Wall
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &6810928998577562200
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6813985912316207378}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 50, y: 0, z: 0}
m_LocalScale: {x: 1, y: 5, z: 101}
m_Children: []
m_Father: {fileID: 6810593986226363672}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &6837517112052221168
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6813985912316207378}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6829370902646183816
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6813985912316207378}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 66163cf35956a4be08e801b750c26f33, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &6805880649474809276
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6813985912316207378}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &6814087175198011730
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6810951867078124798}
- component: {fileID: 6836746497152517328}
- component: {fileID: 6827502220462136834}
- component: {fileID: 6808420949623700432}
m_Layer: 0
m_Name: Wall (2)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &6810951867078124798
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814087175198011730}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 50}
m_LocalScale: {x: 100, y: 5, z: 1}
m_Children: []
m_Father: {fileID: 6810593986226363672}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &6836746497152517328
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814087175198011730}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6827502220462136834
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814087175198011730}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 66163cf35956a4be08e801b750c26f33, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &6808420949623700432
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814087175198011730}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &6814139680395863842
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6817320856451798586}
- component: {fileID: 6837353565563782272}
- component: {fileID: 6829376291544629644}
- component: {fileID: 6808627505318981872}
m_Layer: 0
m_Name: Wall (3)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &6817320856451798586
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814139680395863842}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -50}
m_LocalScale: {x: 100, y: 5, z: 1}
m_Children: []
m_Father: {fileID: 6810593986226363672}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &6837353565563782272
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814139680395863842}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6829376291544629644
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814139680395863842}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 66163cf35956a4be08e801b750c26f33, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &6808627505318981872
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814139680395863842}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &6814265275650057734
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6810815557394078638}
- component: {fileID: 6840107661781754058}
- component: {fileID: 6808624286610137948}
- component: {fileID: 6829276305650059684}
m_Layer: 14
m_Name: Ground
m_TagString: ground
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &6810815557394078638
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814265275650057734}
m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 100, y: 1, z: 100}
m_Children: []
m_Father: {fileID: 6810587057221831324}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!33 &6840107661781754058
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814265275650057734}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!65 &6808624286610137948
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814265275650057734}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &6829276305650059684
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814265275650057734}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: acba6bf2a290a496bb8989b42bf8698d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!1 &6814457128619926090
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6810593986226363672}
m_Layer: 0
m_Name: Walls
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &6810593986226363672
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6814457128619926090}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 2, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 6810928998577562200}
- {fileID: 6810760910859358630}
- {fileID: 6810951867078124798}
- {fileID: 6817320856451798586}
m_Father: {fileID: 6810587057221831324}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &6816166698542906210
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6810760910859358630}
- component: {fileID: 6837318880424580882}
- component: {fileID: 6827488706199143686}
- component: {fileID: 6808790228207097120}
m_Layer: 0
m_Name: Wall (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &6810760910859358630
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6816166698542906210}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -50, y: 0, z: 0}
m_LocalScale: {x: 1, y: 5, z: 101}
m_Children: []
m_Father: {fileID: 6810593986226363672}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &6837318880424580882
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6816166698542906210}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6827488706199143686
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6816166698542906210}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 66163cf35956a4be08e801b750c26f33, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &6808790228207097120
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6816166698542906210}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1001 &1542877156652333457
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 6810587057221831324}
m_Modifications:
- target: {fileID: 1293290366791352, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_Name
value: AgentCube_Blue
objectReference: {fileID: 0}
- target: {fileID: 1293290366791352, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_TagString
value: agent
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalPosition.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalRotation.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 70d695e1d8399400bb0f2873bdf29bb0, type: 3}
--- !u!1 &1544170231188215593 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1293290366791352, guid: 70d695e1d8399400bb0f2873bdf29bb0,
type: 3}
m_PrefabInstance: {fileID: 1542877156652333457}
m_PrefabAsset: {fileID: 0}
--- !u!4 &1547398244452357329 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4521296116772160, guid: 70d695e1d8399400bb0f2873bdf29bb0,
type: 3}
m_PrefabInstance: {fileID: 1542877156652333457}
m_PrefabAsset: {fileID: 0}

7
Project/Assets/ML-Agents/Examples/Crawler/Prefabs/CubePlatform.prefab.meta


fileFormatVersion: 2
guid: 6b57ffcc9ed774f7ba07c429879be03f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Project/Assets/ML-Agents/Examples/Crawler/Scenes/CubeMove.unity
文件差异内容过多而无法显示
查看文件

7
Project/Assets/ML-Agents/Examples/Crawler/Scenes/CubeMove.unity.meta


fileFormatVersion: 2
guid: e51be925339334fd881a1c534a9bbea4
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

204
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CubeAgent.cs


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
using Unity.MLAgents.Sensors;
using Random = UnityEngine.Random;
public class CubeAgent : Agent
{
//float m_LateralSpeed;
//float m_ForwardSpeed;
[HideInInspector]
public Rigidbody agentRb;
BehaviorParameters m_BehaviorParameters;
public Vector3 initialPos;
public GameObject area;
int m_NumDiv = 4;
EnvironmentParameters m_ResetParams;
public Transform TargetPrefab; //Target prefab to use in Dynamic envs
private Transform m_Target; //Target the agent will walk towards during training.
float[] continuousDiv;
VectorSensorComponent m_DiversitySettingSensor;
public bool useContinuous = false;
public int m_DiversitySetting = 0;
[Range(-1f, 1f)]
public float div1;
[Range(-1f, 1f)]
public float div2;
[Range(-1f, 1f)]
public float div3;
[Range(-1f, 1f)]
public float div4;
public override void Initialize()
{
continuousDiv = new float[m_NumDiv];
SpawnTarget(TargetPrefab, transform.position); //spawn target
m_BehaviorParameters = gameObject.GetComponent<BehaviorParameters>();
//m_LateralSpeed = 1.0f;
//m_ForwardSpeed = 1.0f;
GetComponent<VectorSensorComponent>().CreateSensors();
m_DiversitySettingSensor = GetComponent<VectorSensorComponent>();
agentRb = GetComponent<Rigidbody>();
}
void SpawnTarget(Transform prefab, Vector3 pos)
{
m_Target = Instantiate(prefab, pos, Quaternion.identity, transform.parent);
}
public void MoveAgent(ActionBuffers actionBuffers)
{
var dirToGo = Vector3.zero;
var rotateDir = Vector3.zero;
var continuousActions = actionBuffers.ContinuousActions;
var forward = Mathf.Clamp(continuousActions[0], -1f, 1f);
var right = Mathf.Clamp(continuousActions[1], -1f, 1f);
var rotate = Mathf.Clamp(continuousActions[2], -1f, 1f);
dirToGo = transform.forward * forward;
dirToGo += transform.right * right;
rotateDir = -transform.up * rotate;
transform.Rotate(rotateDir, Time.deltaTime * 100f);
agentRb.AddForce(dirToGo,
ForceMode.VelocityChange);
}
public override void OnActionReceived(ActionBuffers actionBuffers)
{
MoveAgent(actionBuffers);
}
void OnCollisionEnter(Collision col)
{
if (col.transform.CompareTag("target"))
{
SetReward(1f);
//EndEpisode();
}
}
public override void CollectObservations(VectorSensor sensor)
{
//AddReward(-1f);
m_DiversitySettingSensor.GetSensor().Reset();
if (useContinuous)
{
Array.Clear(continuousDiv, 0, m_NumDiv);
continuousDiv[0] = div1;
continuousDiv[1] = div2;
continuousDiv[2] = div3;
continuousDiv[3] = div4;
m_DiversitySettingSensor.GetSensor().AddObservation(continuousDiv);
}
else
{
m_DiversitySettingSensor.GetSensor().AddOneHotObservation(m_DiversitySetting, m_NumDiv);
}
//velocity we want to match
//var velGoal = cubeForward * TargetWalkingSpeed;
//ragdoll's avg vel
//var avgVel = GetAvgVelocity();
//current ragdoll velocity. normalized
//sensor.AddObservation(Vector3.Distance(velGoal, avgVel));
//avg body vel relative to cube
//vel goal relative to cube
//rotation delta
//Add pos of target relative to orientation cube
//sensor.AddObservation(Vector3.Dot(agentRb.velocity, agentRb.transform.forward) / 80f);
//sensor.AddObservation(Vector3.Dot(agentRb.velocity, agentRb.transform.right) / 80f);
//sensor.AddObservation(agentRb.transform.forward.x);
//sensor.AddObservation(agentRb.transform.forward.z);
// sensor.AddObservation(transform.InverseTransformPoint(m_Target.transform.position).x / 50f);
// sensor.AddObservation(transform.InverseTransformPoint(m_Target.transform.position).z / 50f);
//sensor.AddObservation((transform.position.x - m_Target.transform.position.x) / 50f);
//sensor.AddObservation((transform.position.z - m_Target.transform.position.z) / 50f);
//sensor.AddObservation(transform.InverseTransformPoint(m_Target.transform.position).z / 50f);
//sensor.AddObservation((transform.position.x - area.transform.position.x) / 50f);
//sensor.AddObservation((transform.position.z - area.transform.position.z) / 50f);
}
public override void Heuristic(in ActionBuffers actionsOut)
{
var continuousActionsOut = actionsOut.ContinuousActions;
if (Input.GetKey(KeyCode.D))
{
continuousActionsOut[2] = -1;
}
if (Input.GetKey(KeyCode.W))
{
continuousActionsOut[0] = 1;
}
if (Input.GetKey(KeyCode.A))
{
continuousActionsOut[2] = 1;
}
if (Input.GetKey(KeyCode.Q))
{
continuousActionsOut[1] = -1;
}
if (Input.GetKey(KeyCode.E))
{
continuousActionsOut[1] = 1;
}
if (Input.GetKey(KeyCode.S))
{
continuousActionsOut[0] = -1;
}
}
/// <summary>
/// Used to provide a "kick" to the ball.
/// </summary>
public override void OnEpisodeBegin()
{
if (useContinuous)
{
Array.Clear(continuousDiv, 0, m_NumDiv);
div1 = Random.Range(-1f, 1f);
div2 = Random.Range(-1f, 1f);
div3 = Random.Range(-1f, 1f);
div4 = Random.Range(-1f, 1f);
continuousDiv[0] = div1;
continuousDiv[1] = div2;
continuousDiv[2] = div3;
continuousDiv[3] = div4;
}
else
{
m_DiversitySetting = Random.Range(0, m_NumDiv);
}
agentRb.velocity = Vector3.zero;
transform.position = new Vector3(Random.Range(-3f, 3f),
1f, Random.Range(-3f, 3f))
+ area.transform.position;
transform.rotation = Quaternion.Euler(new Vector3(0f, Random.Range(0, 360)));
}
}

11
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CubeAgent.cs.meta


fileFormatVersion: 2
guid: c38fe3d08399d4266b7feff82f7a46e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Project/Assets/ML-Agents/Examples/Crawler/TFModels/CubeDiv-984000.onnx
文件差异内容过多而无法显示
查看文件

14
Project/Assets/ML-Agents/Examples/Crawler/TFModels/CubeDiv-984000.onnx.meta


fileFormatVersion: 2
guid: 4ccca19b2537343baa8dc44f367b720f
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3}
optimizeModel: 1
forceArbitraryBatchSize: 1
treatErrorsAsWarnings: 0
importMode: 1

28
config/sac/Cube.yaml


behaviors:
CubeDiv:
trainer_type: sac
hyperparameters:
learning_rate: 0.0003
learning_rate_schedule: constant
batch_size: 256
buffer_size: 500000
buffer_init_steps: 0
tau: 0.005
steps_per_update: 20.0
save_replay_buffer: false
init_entcoef: 1.0
reward_signal_steps_per_update: 20.0
network_settings:
normalize: false
hidden_units: 512
num_layers: 2
vis_encode_type: simple
goal_conditioning_type: none
reward_signals:
extrinsic:
gamma: 0.99
strength: 10.0
keep_checkpoints: 5
max_steps: 5000000
time_horizon: 1000
summary_freq: 3000
正在加载...
取消
保存