HH
5 年前
当前提交
2d2844bd
共有 24 个文件被更改,包括 2051 次插入 和 2162 次删除
-
3Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/JointDriveController.cs
-
29Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerRagdoll.prefab
-
7Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerWithTargetPair.prefab
-
2Project/Assets/ML-Agents/Examples/Walker/Scenes/WalkerStatic.unity
-
42config/ppo/Walker.yaml
-
42config/trainer_config.yaml
-
1001Project/Assets/ExpertWalkerDyn.demo
-
10Project/Assets/ExpertWalkerDyn.demo.meta
-
1001Project/Assets/ML-Agents/Examples/Walker/Demos/ExpertWalkerDyn.demo
-
10Project/Assets/ML-Agents/Examples/Walker/Demos/ExpertWalkerDyn.demo.meta
-
11Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AvgCenterOfMass.cs.meta
-
28Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RagdollHelpers.cs
-
3Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/RagdollHelpers.cs.meta
-
297Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AvgCenterOfMass.cs
-
36Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/MeshSkewFix.cs
-
11Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/MeshSkewFix.cs.meta
-
1001Project/Assets/ML-Agents/Examples/Walker/Demos/ExpertWalker.demo
-
10Project/Assets/ML-Agents/Examples/Walker/Demos/ExpertWalker.demo.meta
-
7Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerPairDynamic.prefab.meta
-
358Project/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerPairDynamic.prefab
-
12Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgentDynamic.cs.meta
-
284Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgentDynamic.cs
-
8Project/Assets/Puppo.meta
|
|||
behaviors: |
|||
Walker: |
|||
trainer_type: ppo |
|||
hyperparameters: |
|||
batch_size: 2048 |
|||
buffer_size: 20480 |
|||
learning_rate: 0.0003 |
|||
beta: 0.005 |
|||
epsilon: 0.2 |
|||
lambd: 0.95 |
|||
num_epoch: 3 |
|||
learning_rate_schedule: linear |
|||
network_settings: |
|||
normalize: true |
|||
hidden_units: 512 |
|||
num_layers: 3 |
|||
vis_encode_type: simple |
|||
trainer: ppo |
|||
batch_size: 2048 |
|||
beta: 0.005 |
|||
buffer_size: 20480 |
|||
epsilon: 0.2 |
|||
hidden_units: 512 |
|||
lambd: 0.95 |
|||
learning_rate: 0.0003 |
|||
learning_rate_schedule: linear |
|||
max_steps: 2e7 |
|||
memory_size: 128 |
|||
normalize: true |
|||
num_epoch: 3 |
|||
num_layers: 3 |
|||
time_horizon: 1000 |
|||
sequence_length: 64 |
|||
summary_freq: 30000 |
|||
use_recurrent: false |
|||
vis_encode_type: simple |
|||
gamma: 0.995 |
|||
output_path: default |
|||
keep_checkpoints: 5 |
|||
max_steps: 20000000 |
|||
time_horizon: 1000 |
|||
summary_freq: 30000 |
|||
threaded: true |
|||
gamma: 0.995 |
1001
Project/Assets/ExpertWalkerDyn.demo
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 48304968c270e4e998199f64b2a18b4e |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ExpertWalkerDyn.demo |
|||
externalObjects: {} |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 7bd65ce151aaa4a41a45312543c56be1, type: 3} |
1001
Project/Assets/ML-Agents/Examples/Walker/Demos/ExpertWalkerDyn.demo
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 870f0916603374b429c92b4e74d912e1 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/Demonstrations/ExpertWalkerDyn.demo |
|||
externalObjects: {} |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 7bd65ce151aaa4a41a45312543c56be1, type: 3} |
|
|||
fileFormatVersion: 2 |
|||
guid: 35bd0d2facf4149ad86cde561dcedd64 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace MLAgentsExamples |
|||
{ |
|||
/// <summary>
|
|||
/// This class contains logic for common ragdoll operations & helper methods.
|
|||
/// </summary>
|
|||
public static class RagdollHelpers |
|||
{ |
|||
/// <summary>
|
|||
//Get Joint Rotation Relative to the Connected Rigidbody
|
|||
//We want to collect this info because it is the actual rotation, not the "target rotation"
|
|||
//..because when the joint is weak, the target rotation will be much different than the actual rotation
|
|||
/// </summary>
|
|||
public static Quaternion GetJointRotation(ConfigurableJoint joint) |
|||
{ |
|||
Quaternion rotDiff = Quaternion.Inverse(joint.connectedBody.transform.rotation) * joint.transform.rotation; |
|||
return(rotDiff); |
|||
// return(Quaternion.FromToRotation(joint.axis, joint.connectedBody.transform.rotation.eulerAngles));
|
|||
} |
|||
|
|||
public static Quaternion GetRotationDelta(Quaternion r1, Quaternion r2) |
|||
{ |
|||
Quaternion rotDiff = Quaternion.Inverse(r1) * r2; |
|||
return(rotDiff); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2b8c368466f64b5d8b4dca532c0a7b3c |
|||
timeCreated: 1588782867 |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
/// <summary>
|
|||
/// Used for visualizing the average center of mass of a ragdoll
|
|||
/// </summary>
|
|||
[DisallowMultipleComponent] |
|||
[ExecuteInEditMode] |
|||
public class AvgCenterOfMass : MonoBehaviour |
|||
{ |
|||
/// <summary>
|
|||
/// Enable to show a green spehere at the current center of mass.
|
|||
/// </summary>
|
|||
[Tooltip("Enable to show a green spehere at the current center of mass.")] |
|||
public bool showCOMGizmos = true; |
|||
public Vector3 avgCOMWorldSpace; |
|||
public Color avgCOMColor = Color.green; |
|||
public Color bodyPartCOMColor = Color.yellow; |
|||
List<Rigidbody> rbList = new List<Rigidbody>(); |
|||
public float totalMass; |
|||
[Tooltip("Visualize Relative Pos")] |
|||
public bool showBPPosRelToBody; |
|||
public bool useTransformPoint = true; |
|||
public bool useTransformVector; |
|||
public bool useTransformDir; |
|||
public bool showRBPos; |
|||
public bool showRelPosVectorOnly; |
|||
public bool showInverseTransformPointUnscaledRelToBody; |
|||
public bool showInverseTransformPointRelToBody; |
|||
public bool showInverseTransformVectorRelToBody; |
|||
public bool showInverseTransformDirRelToBody; |
|||
public Transform body_T; |
|||
void OnEnable() |
|||
{ |
|||
SetUpRigidbodies(); |
|||
} |
|||
|
|||
void SetUpRigidbodies() |
|||
{ |
|||
rbList.Clear(); |
|||
totalMass = 0; |
|||
foreach(var item in GetComponentsInChildren<Rigidbody>()) |
|||
{ |
|||
rbList.Add(item); |
|||
totalMass += item.mass; |
|||
} |
|||
} |
|||
|
|||
// void FixedUpdate()
|
|||
// {
|
|||
// if(Application.isPlaying)
|
|||
// {
|
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
|
|||
// //DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
// }
|
|||
// }
|
|||
|
|||
void FixedUpdate() |
|||
{ |
|||
if(Application.isPlaying) |
|||
{ |
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
// //DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
|
|||
|
|||
Vector3 CoM = Vector3.zero; |
|||
float c = 0f; |
|||
|
|||
foreach(var item in rbList) |
|||
{ |
|||
CoM += item.worldCenterOfMass * item.mass; |
|||
c += item.mass; |
|||
} |
|||
avgCOMWorldSpace = CoM/c; |
|||
// CoM /= c;
|
|||
|
|||
|
|||
if (showBPPosRelToBody) |
|||
{ |
|||
var pos = body_T.position; |
|||
Matrix4x4 bodyMatrix = body_T.localToWorldMatrix; |
|||
// get position from the last column
|
|||
var bodyPos = new Vector3(bodyMatrix[0,3], bodyMatrix[1,3], bodyMatrix[2,3]); |
|||
Debug.DrawRay(bodyPos, Vector3.up, Color.yellow,Time.fixedDeltaTime); |
|||
foreach (var rb in rbList) |
|||
{ |
|||
if (showRBPos) |
|||
{ |
|||
Debug.DrawRay(rb.position, Vector3.up, Color.green,Time.fixedDeltaTime); |
|||
} |
|||
if (rb.transform != body_T) |
|||
{ |
|||
if (showRelPosVectorOnly) |
|||
{ |
|||
var relPosVector = rb.position - body_T.position; |
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
Debug.DrawRay(body_T.position + relPosVector, Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
// Vector3 currentLocalPosRelToMatrix = bodyMatrix.inverse.MultiplyPoint(rb.position);
|
|||
Vector3 currentLocalPosRelToMatrix = bodyMatrix.inverse.MultiplyVector(rb.position - bodyPos); |
|||
|
|||
Debug.DrawRay(body_T.position + currentLocalPosRelToMatrix, Vector3.up, Color.green,Time.fixedDeltaTime); |
|||
} |
|||
if (showInverseTransformPointUnscaledRelToBody) |
|||
{ |
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPointUnscaled(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
Debug.DrawRay(body_T.position + body_T.InverseTransformPointUnscaled(rb.transform.position), Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
} |
|||
if (showInverseTransformPointRelToBody) |
|||
{ |
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
} |
|||
if (showInverseTransformDirRelToBody) |
|||
{ |
|||
Debug.DrawRay(body_T.InverseTransformDirection(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
} |
|||
if (showInverseTransformVectorRelToBody) |
|||
{ |
|||
Debug.DrawRay(body_T.position + body_T.InverseTransformVector(rb.position - body_T.position), Vector3.up, Color.red,Time.fixedDeltaTime); |
|||
} |
|||
// var localPosRelToBody = body.InverseTransformPoint(rb.position);
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformPoint(rb.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + rb.transform.TransformVector(rb.transform.localPosition), Vector3.up, Color.cyan,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(rb.transform.TransformPoint(rb.position), Vector3.up, Color.green,Time.fixedDeltaTime);
|
|||
|
|||
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformVector(rb.transform.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + body_T.InverseTransformDirection(rb.transform.position), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
// Debug.DrawRay(body_T.position + body_T.TransformPoint(rb.transform.localPosition), Vector3.up, Color.red,Time.fixedDeltaTime);
|
|||
|
|||
if (useTransformPoint) |
|||
{ |
|||
|
|||
} |
|||
else if (useTransformVector) |
|||
{ |
|||
|
|||
} |
|||
else if (useTransformDir) |
|||
{ |
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
private void OnDrawGizmosSelected() |
|||
{ |
|||
if(!Application.isPlaying) |
|||
{ |
|||
if (showCOMGizmos) |
|||
{ |
|||
Vector3 CoM = Vector3.zero; |
|||
float c = 0f; |
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
//SHOW BODY PART GIZMOS
|
|||
foreach(var item in rbList) |
|||
{ |
|||
// if (item)
|
|||
// {
|
|||
Gizmos.color = bodyPartCOMColor; |
|||
float drawCOMRadius = item.mass/totalMass; |
|||
Gizmos.DrawSphere(item.worldCenterOfMass, drawCOMRadius); |
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
CoM += item.worldCenterOfMass * item.mass; |
|||
c += item.mass; |
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
} |
|||
|
|||
//DRAW AVG GIZMOS
|
|||
avgCOMWorldSpace = CoM/c; |
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
float avgCOMRadius = 0.1f; //radius of gizmo
|
|||
Gizmos.color = avgCOMColor; |
|||
Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMRadius); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (showCOMGizmos) |
|||
{ |
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
//SHOW BODY PART GIZMOS
|
|||
foreach(var item in rbList) |
|||
{ |
|||
// if (item)
|
|||
// {
|
|||
Gizmos.color = bodyPartCOMColor; |
|||
float drawCOMRadius = item.mass/totalMass; |
|||
Gizmos.DrawSphere(item.worldCenterOfMass, drawCOMRadius); |
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
} |
|||
|
|||
//DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
float avgCOMGizmoRadius = 0.1f; //radius of gizmo
|
|||
Gizmos.color = avgCOMColor; |
|||
Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMGizmoRadius); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
} |
|||
} |
|||
// {
|
|||
// if(!Application.isPlaying)
|
|||
// {
|
|||
// if (showCOMGizmos)
|
|||
// {
|
|||
// avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
// //SHOW BODY PART GIZMOS
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// Gizmos.color = bodyPartCOMColor;
|
|||
// float drawCOMRadius = item.mass/totalMass;
|
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
// avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
|
|||
// //DRAW AVG GIZMOS
|
|||
// avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
// float avgCOMRadius = 0.1f; //radius of gizmo
|
|||
// Gizmos.color = avgCOMColor;
|
|||
// Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMRadius);
|
|||
// }
|
|||
// }
|
|||
// else
|
|||
// {
|
|||
// if (showCOMGizmos)
|
|||
// {
|
|||
// // avgCOMWorldSpace = Vector3.zero;
|
|||
|
|||
// //SHOW BODY PART GIZMOS
|
|||
// foreach(var item in rbList)
|
|||
// {
|
|||
// if (item)
|
|||
// {
|
|||
// Gizmos.color = bodyPartCOMColor;
|
|||
// float drawCOMRadius = item.mass/totalMass;
|
|||
// Gizmos.DrawWireSphere(item.worldCenterOfMass, drawCOMRadius);
|
|||
// // avgCOMWorldSpace += item.worldCenterOfMass;
|
|||
// }
|
|||
// }
|
|||
|
|||
// //DRAW AVG GIZMOS
|
|||
// // avgCOMWorldSpace /= rbList.Count; //divide by num of rb's to get avg in WORLD space
|
|||
// float avgCOMGizmoRadius = 0.1f; //radius of gizmo
|
|||
// Gizmos.color = avgCOMColor;
|
|||
// Gizmos.DrawSphere(avgCOMWorldSpace, avgCOMGizmoRadius);
|
|||
// }
|
|||
|
|||
// }
|
|||
// }
|
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
|
|||
[ExecuteAlways] |
|||
public class MeshSkewFix : MonoBehaviour |
|||
{ |
|||
public bool fix; |
|||
public GameObject rootGameObject; |
|||
// Start is called before the first frame update
|
|||
void Start() |
|||
{ |
|||
|
|||
} |
|||
|
|||
// Update is called once per frame
|
|||
void Update() |
|||
{ |
|||
if (fix) |
|||
{ |
|||
fix = false; |
|||
foreach (var t in GetComponentsInChildren<Transform>()) |
|||
{ |
|||
var joint = t.GetComponent<ConfigurableJoint>(); |
|||
if (joint) |
|||
{ |
|||
var meshFilter = t.GetComponent<MeshFilter>(); |
|||
var meshRend = t.GetComponent<MeshFilter>(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cdd5a22612a4949bbb5672f2dca17d3b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/Walker/Demos/ExpertWalker.demo
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: d75254c9e8cb8402d98eede161c74a60 |
|||
ScriptedImporter: |
|||
fileIDToRecycleName: |
|||
11400000: Assets/ML-Agents/Examples/Walker/Demos/ExpertWalker.demo |
|||
externalObjects: {} |
|||
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)' |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
script: {fileID: 11500000, guid: 7bd65ce151aaa4a41a45312543c56be1, type: 3} |
|
|||
fileFormatVersion: 2 |
|||
guid: 012997b9fa39c4058978e9bd7c81f51d |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!1 &8914216747803489280 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 8908943361521729982} |
|||
m_Layer: 0 |
|||
m_Name: WalkerPairDynamic |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &8908943361521729982 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8914216747803489280} |
|||
m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.70710677} |
|||
m_LocalPosition: {x: -500, y: 2.45, z: -250} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: |
|||
- {fileID: 8916348921871391354} |
|||
- {fileID: 7829202361713789865} |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 90.00001, z: 0} |
|||
--- !u!1 &8914220782118561088 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 8916348921871391354} |
|||
- component: {fileID: 8918560094692032848} |
|||
- component: {fileID: 8888482469445637088} |
|||
- component: {fileID: 8928203313868605220} |
|||
- component: {fileID: 8895238375323918394} |
|||
m_Layer: 0 |
|||
m_Name: Target |
|||
m_TagString: target |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &8916348921871391354 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8914220782118561088} |
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
|||
m_LocalPosition: {x: 0, y: 1.7899997, z: 1800} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: [] |
|||
m_Father: {fileID: 8908943361521729982} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &8918560094692032848 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8914220782118561088} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!65 &8888482469445637088 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8914220782118561088} |
|||
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 &8928203313868605220 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8914220782118561088} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 0 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 1 |
|||
m_RendererPriority: 0 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: c67450f290f3e4897bc40276a619e78d, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 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!54 &8895238375323918394 |
|||
Rigidbody: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 8914220782118561088} |
|||
serializedVersion: 2 |
|||
m_Mass: 5 |
|||
m_Drag: 0 |
|||
m_AngularDrag: 0.05 |
|||
m_UseGravity: 1 |
|||
m_IsKinematic: 0 |
|||
m_Interpolate: 0 |
|||
m_Constraints: 0 |
|||
m_CollisionDetection: 0 |
|||
--- !u!1001 &4697523514811439129 |
|||
PrefabInstance: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 2 |
|||
m_Modification: |
|||
m_TransformParent: {fileID: 8908943361521729982} |
|||
m_Modifications: |
|||
- target: {fileID: 3284846713654268841, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_Name |
|||
value: WalkerRagdollScale1 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.x |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.y |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalPosition.z |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.x |
|||
value: -0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.y |
|||
value: -0.000000059604645 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.z |
|||
value: -0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalRotation.w |
|||
value: 1 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_RootOrder |
|||
value: 1 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalEulerAnglesHint.x |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalEulerAnglesHint.y |
|||
value: 90 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalEulerAnglesHint.z |
|||
value: 0 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalScale.x |
|||
value: 1.0000004 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_LocalScale.z |
|||
value: 1.0000004 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 3284846713654268850, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: target |
|||
value: |
|||
objectReference: {fileID: 8916348921871391354} |
|||
- target: {fileID: 3284846713654268851, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_Model |
|||
value: |
|||
objectReference: {fileID: 11400000, guid: e1adbf3a9d04441259d6327d42fcce3d, |
|||
type: 3} |
|||
- target: {fileID: 5756232957735828584, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: -0.00000020861626 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232957735828584, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: 0.000000011921652 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232957926479945, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: -0.00000020861626 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232957926479945, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: 0.000000011921652 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232957927770494, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: 0.39999375 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232957927770494, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: 0.000000011921652 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958318828577, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: -0.6999967 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958318828577, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: 0.000000023841485 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958328739261, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: -0.6999959 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958328739261, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: 0.00000011324842 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958382481510, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: -0.39999375 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958382481510, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: -0.000000011921652 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958394302960, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: -0.49999928 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958394302960, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: -0.000000029802312 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958426567217, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: 0.00000020861626 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958426567217, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: -0.000000011921652 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958482997937, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: 0.49999928 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958482997937, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: 0.000000029802312 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958734302659, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: 0.6999967 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958734302659, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: -0.000000023841485 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958961935667, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: 0.00000020861626 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232958961935667, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: -0.000000011921652 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232959234071936, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.x |
|||
value: 0.6999959 |
|||
objectReference: {fileID: 0} |
|||
- target: {fileID: 5756232959234071936, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
propertyPath: m_ConnectedAnchor.z |
|||
value: -0.00000011324842 |
|||
objectReference: {fileID: 0} |
|||
m_RemovedComponents: [] |
|||
m_SourcePrefab: {fileID: 100100000, guid: 80520f477184d46c8841239b4a818a3e, type: 3} |
|||
--- !u!4 &7829202361713789865 stripped |
|||
Transform: |
|||
m_CorrespondingSourceObject: {fileID: 3284846713654268848, guid: 80520f477184d46c8841239b4a818a3e, |
|||
type: 3} |
|||
m_PrefabInstance: {fileID: 4697523514811439129} |
|||
m_PrefabAsset: {fileID: 0} |
|
|||
fileFormatVersion: 2 |
|||
guid: 21bcc2d3e08144151a0df9fa506dbbe7 |
|||
timeCreated: 1507411991 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using MLAgentsExamples; |
|||
using UnityEngine; |
|||
using Unity.MLAgents; |
|||
using Unity.MLAgentsExamples; |
|||
using Unity.MLAgents.Sensors; |
|||
using UnityEditor; |
|||
using BodyPart = Unity.MLAgentsExamples.BodyPart; |
|||
|
|||
public class WalkerAgentDynamic : Agent |
|||
{ |
|||
[Header("Walking Speed")] |
|||
[Space(10)] |
|||
[Header("Specific to Walker")] |
|||
public float maximumWalkingSpeed = 999; //The max walk velocity magnitude an agent will be rewarded for
|
|||
Vector3 m_WalkDir; |
|||
Quaternion m_WalkDirLookRot; |
|||
|
|||
[Space(10)] |
|||
[Header("Orientation Cube")] |
|||
[Space(10)] |
|||
//This will be used as a stable observation platform for the ragdoll to use.
|
|||
GameObject m_OrientationCube; |
|||
public Transform directionIndicator; |
|||
|
|||
[Header("Target To Walk Towards")] |
|||
[Space(10)] |
|||
public float targetSpawnRadius; |
|||
public Transform target; |
|||
public Transform ground; |
|||
public bool detectTargets; |
|||
public bool targetIsStatic; |
|||
public bool respawnTargetWhenTouched; |
|||
|
|||
|
|||
[Header("Body Parts")] |
|||
[Space(10)] |
|||
public Transform hips; |
|||
public Transform chest; |
|||
public Transform spine; |
|||
public Transform head; |
|||
public Transform thighL; |
|||
public Transform shinL; |
|||
public Transform footL; |
|||
public Transform thighR; |
|||
public Transform shinR; |
|||
public Transform footR; |
|||
public Transform armL; |
|||
public Transform forearmL; |
|||
public Transform handL; |
|||
public Transform armR; |
|||
public Transform forearmR; |
|||
public Transform handR; |
|||
JointDriveController m_JdController; |
|||
|
|||
Rigidbody m_HipsRb; |
|||
Rigidbody m_ChestRb; |
|||
Rigidbody m_SpineRb; |
|||
|
|||
EnvironmentParameters m_ResetParams; |
|||
|
|||
|
|||
|
|||
public override void Initialize() |
|||
{ |
|||
//Spawn an orientation cube
|
|||
Vector3 oCubePos = hips.position; |
|||
oCubePos.y = -.45f; |
|||
m_OrientationCube = Instantiate(Resources.Load<GameObject>("OrientationCube"), oCubePos, Quaternion.identity); |
|||
m_OrientationCube.transform.SetParent(transform); |
|||
|
|||
UpdateOrientationCube(); |
|||
|
|||
m_JdController = GetComponent<JointDriveController>(); |
|||
m_JdController.SetupBodyPart(hips); |
|||
m_JdController.SetupBodyPart(chest); |
|||
m_JdController.SetupBodyPart(spine); |
|||
m_JdController.SetupBodyPart(head); |
|||
m_JdController.SetupBodyPart(thighL); |
|||
m_JdController.SetupBodyPart(shinL); |
|||
m_JdController.SetupBodyPart(footL); |
|||
m_JdController.SetupBodyPart(thighR); |
|||
m_JdController.SetupBodyPart(shinR); |
|||
m_JdController.SetupBodyPart(footR); |
|||
m_JdController.SetupBodyPart(armL); |
|||
m_JdController.SetupBodyPart(forearmL); |
|||
m_JdController.SetupBodyPart(handL); |
|||
m_JdController.SetupBodyPart(armR); |
|||
m_JdController.SetupBodyPart(forearmR); |
|||
m_JdController.SetupBodyPart(handR); |
|||
|
|||
m_HipsRb = hips.GetComponent<Rigidbody>(); |
|||
m_ChestRb = chest.GetComponent<Rigidbody>(); |
|||
m_SpineRb = spine.GetComponent<Rigidbody>(); |
|||
|
|||
m_ResetParams = Academy.Instance.EnvironmentParameters; |
|||
|
|||
SetResetParameters(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Add relevant information on each body part to observations.
|
|||
/// </summary>
|
|||
public void CollectObservationBodyPart(BodyPart bp, VectorSensor sensor) |
|||
{ |
|||
//GROUND CHECK
|
|||
sensor.AddObservation(bp.groundContact.touchingGround ? 1 : 0); // Is this bp touching the ground
|
|||
|
|||
//Get velocities in the context of our orientation cube's space
|
|||
//Note: You can get these velocities in world space as well but it may not train as well.
|
|||
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(bp.rb.velocity)); |
|||
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(bp.rb.angularVelocity)); |
|||
|
|||
//Get position relative to hips in the context of our orientation cube's space
|
|||
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(bp.rb.position - hips.position)); //best
|
|||
|
|||
if (bp.rb.transform != hips && bp.rb.transform != handL && bp.rb.transform != handR) |
|||
{ |
|||
sensor.AddObservation(bp.rb.transform.localRotation); |
|||
sensor.AddObservation(bp.currentStrength / m_JdController.maxJointForceLimit); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loop over body parts to add them to observation.
|
|||
/// </summary>
|
|||
public override void CollectObservations(VectorSensor sensor) |
|||
{ |
|||
sensor.AddObservation(Quaternion.FromToRotation(hips.forward, m_OrientationCube.transform.forward)); |
|||
sensor.AddObservation(Quaternion.FromToRotation(head.forward, m_OrientationCube.transform.forward)); |
|||
|
|||
foreach (var bodyPart in m_JdController.bodyPartsDict.Values) |
|||
{ |
|||
CollectObservationBodyPart(bodyPart, sensor); |
|||
} |
|||
} |
|||
|
|||
public override void OnActionReceived(float[] vectorAction) |
|||
{ |
|||
var bpDict = m_JdController.bodyPartsDict; |
|||
var i = -1; |
|||
|
|||
bpDict[chest].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]); |
|||
bpDict[spine].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]); |
|||
|
|||
bpDict[thighL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[thighR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[shinL].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[shinR].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[footR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]); |
|||
bpDict[footL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]); |
|||
|
|||
bpDict[armL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[armR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
bpDict[forearmL].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[forearmR].SetJointTargetRotation(vectorAction[++i], 0, 0); |
|||
bpDict[head].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0); |
|||
|
|||
//update joint strength settings
|
|||
bpDict[chest].SetJointStrength(vectorAction[++i]); |
|||
bpDict[spine].SetJointStrength(vectorAction[++i]); |
|||
bpDict[head].SetJointStrength(vectorAction[++i]); |
|||
bpDict[thighL].SetJointStrength(vectorAction[++i]); |
|||
bpDict[shinL].SetJointStrength(vectorAction[++i]); |
|||
bpDict[footL].SetJointStrength(vectorAction[++i]); |
|||
bpDict[thighR].SetJointStrength(vectorAction[++i]); |
|||
bpDict[shinR].SetJointStrength(vectorAction[++i]); |
|||
bpDict[footR].SetJointStrength(vectorAction[++i]); |
|||
bpDict[armL].SetJointStrength(vectorAction[++i]); |
|||
bpDict[forearmL].SetJointStrength(vectorAction[++i]); |
|||
bpDict[armR].SetJointStrength(vectorAction[++i]); |
|||
bpDict[forearmR].SetJointStrength(vectorAction[++i]); |
|||
} |
|||
|
|||
void UpdateOrientationCube() |
|||
{ |
|||
//FACING DIR
|
|||
m_WalkDir = target.position - m_OrientationCube.transform.position; |
|||
m_WalkDir.y = 0; //flatten dir on the y
|
|||
m_WalkDirLookRot = Quaternion.LookRotation(m_WalkDir); //get our look rot to the target
|
|||
|
|||
//UPDATE ORIENTATION CUBE POS & ROT
|
|||
m_OrientationCube.transform.position = hips.position; |
|||
m_OrientationCube.transform.rotation = m_WalkDirLookRot; |
|||
|
|||
directionIndicator.position = new Vector3(hips.position.x, directionIndicator.position.y, hips.position.z); |
|||
directionIndicator.rotation = m_WalkDirLookRot; |
|||
} |
|||
|
|||
void FixedUpdate() |
|||
{ |
|||
if (detectTargets) |
|||
{ |
|||
foreach (var bodyPart in m_JdController.bodyPartsDict.Values) |
|||
{ |
|||
if (bodyPart.targetContact && bodyPart.targetContact.touchingTarget) |
|||
{ |
|||
TouchedTarget(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
UpdateOrientationCube(); |
|||
|
|||
// Set reward for this step according to mixture of the following elements.
|
|||
// a. Velocity alignment with goal direction.
|
|||
// b. Rotation alignment with goal direction.
|
|||
// c. Encourage head height.
|
|||
AddReward( |
|||
+0.02f * Vector3.Dot(m_OrientationCube.transform.forward, |
|||
Vector3.ClampMagnitude(m_JdController.bodyPartsDict[hips].rb.velocity, maximumWalkingSpeed)) |
|||
+ 0.01f * Vector3.Dot(m_OrientationCube.transform.forward, head.forward) |
|||
+ 0.005f * (head.position.y - footL.position.y) |
|||
+ 0.005f * (head.position.y - footR.position.y) |
|||
); |
|||
} |
|||
|
|||
/// <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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Loop over body parts and reset them to initial conditions.
|
|||
/// </summary>
|
|||
public override void OnEpisodeBegin() |
|||
{ |
|||
foreach (var bodyPart in m_JdController.bodyPartsDict.Values) |
|||
{ |
|||
bodyPart.Reset(bodyPart); |
|||
} |
|||
|
|||
//Random start rotation
|
|||
transform.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0); |
|||
|
|||
UpdateOrientationCube(); |
|||
|
|||
if (detectTargets && !targetIsStatic) |
|||
{ |
|||
GetRandomTargetPos(); |
|||
} |
|||
|
|||
SetResetParameters(); |
|||
} |
|||
|
|||
public void SetTorsoMass() |
|||
{ |
|||
m_ChestRb.mass = m_ResetParams.GetWithDefault("chest_mass", 8); |
|||
m_SpineRb.mass = m_ResetParams.GetWithDefault("spine_mass", 10); |
|||
m_HipsRb.mass = m_ResetParams.GetWithDefault("hip_mass", 15); |
|||
} |
|||
|
|||
public void SetResetParameters() |
|||
{ |
|||
SetTorsoMass(); |
|||
} |
|||
|
|||
private void OnDrawGizmosSelected() |
|||
{ |
|||
if (Application.isPlaying) |
|||
{ |
|||
Gizmos.color = Color.green; |
|||
Gizmos.matrix = m_OrientationCube.transform.localToWorldMatrix; |
|||
Gizmos.DrawWireCube(Vector3.zero, m_OrientationCube.transform.localScale); |
|||
Gizmos.DrawRay(Vector3.zero, Vector3.forward); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8fe7964b5935448bbb5ea7625e228d8e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue