浏览代码

creature crawler working

/hh-develop-gridsensor-tests/static
HH 4 年前
当前提交
ac3b8705
共有 32 个文件被更改,包括 7289 次插入14 次删除
  1. 980
      Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerDynamicVariableSpeed.unity
  2. 6
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
  3. 33
      Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockGridSensor.unity
  4. 950
      Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockGridSensorTests.unity
  5. 2
      Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockGridSensorTests.unity.meta
  6. 138
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AgentCubeMovement.cs
  7. 1001
      Project/Assets/ML-Agents/Examples/Crawler/Prefabs/CreaturePlatform.prefab
  8. 7
      Project/Assets/ML-Agents/Examples/Crawler/Prefabs/CreaturePlatform.prefab.meta
  9. 1001
      Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerGRAVEYARD.unity
  10. 7
      Project/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerGRAVEYARD.unity.meta
  11. 411
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CreatureAgent.cs
  12. 13
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CreatureAgent.cs.meta
  13. 1001
      Project/Assets/ML-Agents/Examples/Crawler/TFModels/Creature2Legs.nn
  14. 11
      Project/Assets/ML-Agents/Examples/Crawler/TFModels/Creature2Legs.nn.meta
  15. 78
      Project/Assets/ML-Agents/Examples/SharedAssets/Materials/MOON.mat
  16. 8
      Project/Assets/ML-Agents/Examples/SharedAssets/Materials/MOON.mat.meta
  17. 77
      Project/Assets/ML-Agents/Examples/SharedAssets/Materials/ProjectileMat.mat
  18. 10
      Project/Assets/ML-Agents/Examples/SharedAssets/Materials/ProjectileMat.mat.meta
  19. 78
      Project/Assets/ML-Agents/Examples/SharedAssets/Materials/WhiteEmissive.mat
  20. 8
      Project/Assets/ML-Agents/Examples/SharedAssets/Materials/WhiteEmissive.mat.meta
  21. 634
      Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/PlayerCubeWithGun.prefab
  22. 7
      Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/PlayerCubeWithGun.prefab.meta
  23. 129
      Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/Projectile.prefab
  24. 7
      Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/Projectile.prefab.meta
  25. 81
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AgentCubeGroundCheck.cs
  26. 11
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AgentCubeGroundCheck.cs.meta
  27. 355
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AvgCenterOfMass.cs
  28. 11
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AvgCenterOfMass.cs.meta
  29. 84
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Projectile.cs
  30. 11
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Projectile.cs.meta
  31. 142
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ShootProjectiles.cs
  32. 11
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ShootProjectiles.cs.meta

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

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


private bool m_RandomizeWalkSpeedEachEpisode;
//The direction an agent will walk during training.
[Header("Target To Walk Towards")] public Transform dynamicTargetPrefab; //Target prefab to use in Dynamic envs
[Header("Target To Walk Towards")]
public Transform dynamicTargetPrefab; //Target prefab to use in Dynamic envs
private Transform m_Target; //Target the agent will walk towards during training.
public Transform m_Target; //Target the agent will walk towards during training.
[Header("Body Parts")] [Space(10)] public Transform body;
public Transform leg0Upper;

33
Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockGridSensor.unity


- component: {fileID: 1874930971}
- component: {fileID: 1874930970}
- component: {fileID: 1874930969}
- component: {fileID: 1874930972}
m_Layer: 0
m_Name: Agent (1)
m_TagString: agent

m_IsActive: 0
m_IsActive: 1
--- !u!4 &1874930968
Transform:
m_ObjectHideFlags: 0

agentRunSpeed: 20
agentRunInAirSpeed: 10
agentIdleDragVelCoeff: 0.85
agentRotationSpeed: 7
agentRotationSpeed: 15
agentJumpVelocity: 15
agentFallingSpeed: 50
--- !u!65 &1874930970

m_GameObject: {fileID: 1874930967}
serializedVersion: 2
m_Mass: 10
m_Drag: 4
m_Drag: 0.05
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0

--- !u!114 &1874930972
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1874930967}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 491a09f8a027b44ce87fc4c37f18547f, type: 3}
m_Name:
m_EditorClassIdentifier:
debugDrawGizmos: 1
hitGroundColliders:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
groundCheckBoxLocalPos: {x: 0, y: -0.52, z: 0}
groundCheckBoxSize: {x: 0.99, y: 0.02, z: 0.99}
isGrounded: 0
ungroundedTime: 0
groundedTime: 0
--- !u!1001 &1900462655
PrefabInstance:
m_ObjectHideFlags: 0

- target: {fileID: 5954304494433716804, guid: 9f61863318eba452baefa644fe4ddf1e,
type: 3}
propertyPath: m_IsActive
value: 1
value: 0
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5955804999460259248, guid: 9f61863318eba452baefa644fe4ddf1e,
type: 3}

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

2
Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockGridSensorTests.unity.meta


fileFormatVersion: 2
guid: 1c60968f826d444f1adf1b1256a326ba
guid: b68232994a8ea4244b160a129773b08e
timeCreated: 1506808980
licenseType: Pro
DefaultImporter:

138
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AgentCubeMovement.cs


//Standardized movement controller for the Agent Cube
using System;
using Unity.Mathematics;
using UnityEngine;
namespace MLAgents

[Header("RIGIDBODY")] public float maxAngularVel = 50;
public float agentTerminalVel = 20;
[Header("DASH")]
public float dashBoostForce = 10f;
public ForceMode dashForceMode = ForceMode.Impulse;
public bool dashPressed;
[Header("IDLE")]
//coefficient used to dampen velocity when idle
//the purpose of this is to fine tune agent drag

public float agentIdleDragVelCoeff = .85f;
[Header("GROUND POUND")]
public ForceMode groundPoundForceMode = ForceMode.Impulse;
public float groundPoundForce = 35f;
[Header("SPIN ATTACK")]
public float spinAttackSpeed = 7f;
private bool spinAttack;
[Header("BODY ROTATION")]
//body rotation speed

//upward jump velocity magnitude
//upward jump velocity magnitude
public float agentJumpVelocity = 15f;
[Header("FALLING FORCE")]

private Camera cam;
private Vector3 lookDir;
private Rigidbody rb;
private AgentCubeGroundCheck groundCheck;
void Awake()
{
cam = Camera.main;
rb = GetComponent<Rigidbody>();
groundCheck = GetComponent<AgentCubeGroundCheck>();
rb.maxAngularVelocity = maxAngularVel;
}
void Update()
{
var camForward = cam.transform.forward;
camForward.y = 0;
var camRight = cam.transform.right;
lookDir = Vector3.zero;
lookDir += Input.GetKey(KeyCode.D) ? Vector3.right : Vector3.zero;
lookDir += Input.GetKey(KeyCode.W) ? Vector3.forward : Vector3.zero;
lookDir += Input.GetKey(KeyCode.A) ? Vector3.left : Vector3.zero;
lookDir += Input.GetKey(KeyCode.S) ? Vector3.back : Vector3.zero;
if (Input.GetKeyDown(KeyCode.Space))
{
if (groundCheck)
{
if (groundCheck.isGrounded)
{
Jump(rb);
}
else
{
rb.AddForce(Vector3.down * groundPoundForce, groundPoundForceMode);
}
}
}
spinAttack = Input.GetKey(KeyCode.H);
dashPressed = Input.GetKeyDown(KeyCode.K);
if (dashPressed)
{
// dashPressed = false;
// rb.AddForce(rb.transform.forward * dashBoostForce, dashForceMode);
rb.AddTorque(rb.transform.right * dashBoostForce, dashForceMode);
print("dashPressed");
}
// if (Input.GetKey(KeyCode.D))
// {
// discreteActionsOut[0] = 3;
// }
// else if (Input.GetKey(KeyCode.W))
// {
// discreteActionsOut[0] = 1;
// }
// else if (Input.GetKey(KeyCode.A))
// {
// discreteActionsOut[0] = 4;
// }
// else if (Input.GetKey(KeyCode.S))
// {
// discreteActionsOut[0] = 2;
// }
}
void FixedUpdate()
{
if (spinAttack)
{
// rb.AddTorque(Vector3.up * spinAttackSpeed);
rb.angularVelocity = Vector3.up * spinAttackSpeed;
}
if (lookDir != Vector3.zero)
{
var dir = cam.transform.TransformDirection(lookDir);
dir.y = 0;
var rot = quaternion.LookRotation(dir, Vector3.up);
if (!spinAttack)
{
rb.rotation = Quaternion.Lerp(rb.rotation, rot, agentRotationSpeed * Time.deltaTime);
}
// RunOnGround(rb, dir.normalized);
// var dirToGo = rb.transform.forward;
var dirToGo = dir;
// RunOnGround(rb, dirToGo);
if (!groundCheck.isGrounded)
{
// RunInAir(rb, dirToGo.normalized);
}
else
{
RunOnGround(rb, dirToGo.normalized);
}
// rb.MoveRotation(rb.rotation * Quaternion.AngleAxis(agentRotationSpeed, rotationAxis));
}
else //is idle
{
if (groundCheck && groundCheck.isGrounded && !dashPressed)
{
AddIdleDrag(rb);
}
}
if (groundCheck && !groundCheck.isGrounded)
{
AddFallingForce(rb);
}
}
public void Jump(Rigidbody rb)
{
Vector3 velToUse = rb.velocity;

public void RunOnGround(Rigidbody rb, Vector3 dir)
{
var vel = rb.velocity.magnitude;
float adjustedSpeed = Mathf.Clamp(agentRunSpeed - vel, 0, agentRunSpeed);
float adjustedSpeed = Mathf.Clamp(agentRunSpeed - vel, 0, agentTerminalVel);
rb.AddForce(dir.normalized * adjustedSpeed,
runningForceMode);
}

var vel = rb.velocity.magnitude;
float adjustedSpeed = Mathf.Clamp(agentRunInAirSpeed - vel, 0, agentRunInAirSpeed);
float adjustedSpeed = Mathf.Clamp(agentRunInAirSpeed - vel, 0, agentTerminalVel);
rb.AddForce(dir.normalized * adjustedSpeed,
runningForceMode);
}

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

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


fileFormatVersion: 2
guid: ceb215c8c337148d4b7a279c1cbe8346
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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

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


fileFormatVersion: 2
guid: 107f7bd9f46354507912c9f9c1e8f528
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

411
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CreatureAgent.cs


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.Barracuda;
using Unity.MLAgents.Actuators;
using Unity.MLAgentsExamples;
using Unity.MLAgents.Sensors;
using Random = UnityEngine.Random;
[RequireComponent(typeof(JointDriveController))] // Required to set joint forces
public class CreatureAgent : Agent
{
//The type of crawler behavior we want to use.
//This setting will determine how the agent is set up during initialization.
public enum CrawlerAgentBehaviorType
{
CrawlerDynamic,
CrawlerDynamicVariableSpeed,
CrawlerStatic,
CrawlerStaticVariableSpeed
}
[Tooltip(
"VariableSpeed - The agent will sample random speed magnitudes while training.\n" +
"Dynamic - The agent will run towards a target that changes position.\n" +
"Static - The agent will run towards a static target. "
)]
public CrawlerAgentBehaviorType typeOfCrawler;
//Crawler Brains
//A different brain will be used depending on the CrawlerAgentBehaviorType selected
[Header("NN Models")] public NNModel crawlerDyModel;
public NNModel crawlerDyVSModel;
public NNModel crawlerStModel;
public NNModel crawlerStVSModel;
[Header("Walk Speed")]
[Range(m_minWalkingSpeed, m_maxWalkingSpeed)]
[SerializeField]
[Tooltip(
"The speed the agent will try to match.\n\n" +
"TRAINING:\n" +
"For VariableSpeed envs, this value will randomize at the start of each training episode.\n" +
"Otherwise the agent will try to match the speed set here.\n\n" +
"INFERENCE:\n" +
"During inference, VariableSpeed agents will modify their behavior based on this value " +
"whereas the CrawlerDynamic & CrawlerStatic agents will run at the speed specified during training "
)]
//The walking speed to try and achieve
private float m_TargetWalkingSpeed = m_maxWalkingSpeed;
const float m_minWalkingSpeed = 5; //The max walking speed
const float m_maxWalkingSpeed = 15; //The max walking speed
//The current target walking speed. Clamped because a value of zero will cause NaNs
public float TargetWalkingSpeed
{
get { return m_TargetWalkingSpeed; }
set { m_TargetWalkingSpeed = Mathf.Clamp(value, m_minWalkingSpeed, m_maxWalkingSpeed); }
}
//Should the agent sample a new goal velocity each episode?
//If true, TargetWalkingSpeed will be randomly set between 0.1 and m_maxWalkingSpeed in OnEpisodeBegin()
//If false, the goal velocity will be m_maxWalkingSpeed
private bool m_RandomizeWalkSpeedEachEpisode;
//The direction an agent will walk during training.
[Header("Target To Walk Towards")]
public Transform dynamicTargetPrefab; //Target prefab to use in Dynamic envs
public Transform staticTargetPrefab; //Target prefab to use in Static envs
public Transform m_Target; //Target the agent will walk towards during training.
[Header("Body Parts")] [Space(10)] public Transform body;
public Transform leg0Upper;
public Transform leg0Lower;
public Transform leg1Upper;
public Transform leg1Lower;
public Transform leg2Upper;
public Transform leg2Lower;
public Transform leg3Upper;
public Transform leg3Lower;
//This will be used as a stabilized model space reference point for observations
//Because ragdolls can move erratically during training, using a stabilized reference transform improves learning
OrientationCubeController m_OrientationCube;
//The indicator graphic gameobject that points towards the target
DirectionIndicator m_DirectionIndicator;
JointDriveController m_JdController;
[Header("Foot Grounded Visualization")]
[Space(10)]
public bool useFootGroundedVisualization;
public MeshRenderer foot0;
public MeshRenderer foot1;
public MeshRenderer foot2;
public MeshRenderer foot3;
public Material groundedMaterial;
public Material unGroundedMaterial;
private Vector3 m_StartingPos; //starting position of the agent
public override void Initialize()
{
SetAgentType();
m_StartingPos = body.position;
m_OrientationCube = GetComponentInChildren<OrientationCubeController>();
m_DirectionIndicator = GetComponentInChildren<DirectionIndicator>();
m_JdController = GetComponent<JointDriveController>();
//Setup each body part
m_JdController.SetupBodyPart(body);
m_JdController.SetupBodyPart(leg0Upper);
m_JdController.SetupBodyPart(leg0Lower);
m_JdController.SetupBodyPart(leg1Upper);
m_JdController.SetupBodyPart(leg1Lower);
m_JdController.SetupBodyPart(leg2Upper);
m_JdController.SetupBodyPart(leg2Lower);
m_JdController.SetupBodyPart(leg3Upper);
m_JdController.SetupBodyPart(leg3Lower);
}
/// <summary>
/// Spawns a target prefab at pos
/// </summary>
/// <param name="prefab"></param>
/// <param name="pos"></param>
void SpawnTarget(Transform prefab, Vector3 pos)
{
m_Target = Instantiate(prefab, pos, Quaternion.identity, transform);
}
/// <summary>
/// Set up the agent based on the typeOfCrawler
/// </summary>
void SetAgentType()
{
var behaviorParams = GetComponent<Unity.MLAgents.Policies.BehaviorParameters>();
switch (typeOfCrawler)
{
case CrawlerAgentBehaviorType.CrawlerDynamic:
{
behaviorParams.BehaviorName = "CrawlerDynamic"; //set behavior name
if (crawlerDyModel)
behaviorParams.Model = crawlerDyModel; //assign the model
m_RandomizeWalkSpeedEachEpisode = false; //do not randomize m_TargetWalkingSpeed during training
SpawnTarget(dynamicTargetPrefab, transform.position); //spawn target
break;
}
case CrawlerAgentBehaviorType.CrawlerDynamicVariableSpeed:
{
behaviorParams.BehaviorName = "CrawlerDynamicVariableSpeed"; //set behavior name
if (crawlerDyVSModel)
behaviorParams.Model = crawlerDyVSModel; //assign the model
m_RandomizeWalkSpeedEachEpisode = true; //randomize m_TargetWalkingSpeed during training
SpawnTarget(dynamicTargetPrefab, transform.position); //spawn target
break;
}
case CrawlerAgentBehaviorType.CrawlerStatic:
{
behaviorParams.BehaviorName = "CrawlerStatic"; //set behavior name
if (crawlerStModel)
behaviorParams.Model = crawlerStModel; //assign the model
m_RandomizeWalkSpeedEachEpisode = false; //do not randomize m_TargetWalkingSpeed during training
SpawnTarget(staticTargetPrefab, transform.TransformPoint(new Vector3(0, 0, 1000))); //spawn target
break;
}
case CrawlerAgentBehaviorType.CrawlerStaticVariableSpeed:
{
behaviorParams.BehaviorName = "CrawlerStaticVariableSpeed"; //set behavior name
if (crawlerStVSModel)
behaviorParams.Model = crawlerStVSModel; //assign the model
m_RandomizeWalkSpeedEachEpisode = true; //randomize m_TargetWalkingSpeed during training
SpawnTarget(staticTargetPrefab, transform.TransformPoint(new Vector3(0, 0, 1000))); //spawn target
break;
}
}
}
/// <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 to help generalize
body.rotation = Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0);
UpdateOrientationObjects();
//Set our goal walking speed
TargetWalkingSpeed =
m_RandomizeWalkSpeedEachEpisode ? Random.Range(m_minWalkingSpeed, m_maxWalkingSpeed) : TargetWalkingSpeed;
}
/// <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); // Is this bp touching the ground
if (bp.rb.transform != body)
{
sensor.AddObservation(bp.currentStrength / m_JdController.maxJointForceLimit);
}
}
/// <summary>
/// Loop over body parts to add them to observation.
/// </summary>
public override void CollectObservations(VectorSensor sensor)
{
var cubeForward = m_OrientationCube.transform.forward;
//velocity we want to match
var velGoal = cubeForward * TargetWalkingSpeed;
//ragdoll's avg vel
var avgVel = GetAvgVelocity();
// sensor.AddObservation((Vector3.Dot(cubeForward, body.forward) + 1) * .5F);
// sensor.AddObservation((Vector3.Dot(m_OrientationCube.transform.up, body.up) + 1) * .5F);
//current ragdoll velocity. normalized
sensor.AddObservation(Vector3.Distance(velGoal, avgVel));
//avg body vel relative to cube
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(avgVel));
//vel goal relative to cube
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(velGoal));
// //rotation delta
sensor.AddObservation(Quaternion.FromToRotation(body.forward, cubeForward));
//Add pos of target relative to orientation cube
sensor.AddObservation(m_OrientationCube.transform.InverseTransformPoint(m_Target.transform.position));
// RaycastHit hit;
// float maxRaycastDist = 10;
//// if (Physics.Raycast(body.position, Vector3.down, out hit, maxRaycastDist))
// if (Physics.Raycast(body.position, -body.up, out hit, maxRaycastDist))
// {
// sensor.AddObservation(hit.distance / maxRaycastDist);
// }
// else
// sensor.AddObservation(1);
foreach (var bodyPart in m_JdController.bodyPartsList)
{
CollectObservationBodyPart(bodyPart, sensor);
}
}
public override void OnActionReceived(ActionBuffers actionBuffers)
{
// The dictionary with all the body parts in it are in the jdController
var bpDict = m_JdController.bodyPartsDict;
var continuousActions = actionBuffers.ContinuousActions;
var i = -1;
// Pick a new target joint rotation
bpDict[leg0Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg1Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg2Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg3Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg0Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[leg1Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[leg2Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[leg3Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
// Update joint strength
bpDict[leg0Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg1Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg2Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg3Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg0Lower].SetJointStrength(continuousActions[++i]);
bpDict[leg1Lower].SetJointStrength(continuousActions[++i]);
bpDict[leg2Lower].SetJointStrength(continuousActions[++i]);
bpDict[leg3Lower].SetJointStrength(continuousActions[++i]);
//Reset if Worm fell through floor;
if (body.position.y < m_StartingPos.y - 5)
{
EndEpisode();
}
}
// public override void OnActionReceived(ActionBuffers actionBuffers)
// {
// // The dictionary with all the body parts in it are in the jdController
// var bpDict = m_JdController.bodyPartsDict;
//
// var continuousActions = actionBuffers.ContinuousActions;
// var i = -1;
// // Pick a new target joint rotation
// bpDict[leg0Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
//// bpDict[leg1Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
// bpDict[leg2Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
//// bpDict[leg3Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
// bpDict[leg0Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
//// bpDict[leg1Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
// bpDict[leg2Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
//// bpDict[leg3Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
//
// // Update joint strength
// bpDict[leg0Upper].SetJointStrength(continuousActions[++i]);
//// bpDict[leg1Upper].SetJointStrength(continuousActions[++i]);
// bpDict[leg2Upper].SetJointStrength(continuousActions[++i]);
//// bpDict[leg3Upper].SetJointStrength(continuousActions[++i]);
// bpDict[leg0Lower].SetJointStrength(continuousActions[++i]);
//// bpDict[leg1Lower].SetJointStrength(continuousActions[++i]);
// bpDict[leg2Lower].SetJointStrength(continuousActions[++i]);
//// bpDict[leg3Lower].SetJointStrength(continuousActions[++i]);
// }
void FixedUpdate()
{
UpdateOrientationObjects();
// If enabled the feet will light up green when the foot is grounded.
// This is just a visualization and isn't necessary for function
if (useFootGroundedVisualization)
{
foot0.material = m_JdController.bodyPartsDict[leg0Lower].groundContact.touchingGround
? groundedMaterial
: unGroundedMaterial;
foot1.material = m_JdController.bodyPartsDict[leg1Lower].groundContact.touchingGround
? groundedMaterial
: unGroundedMaterial;
foot2.material = m_JdController.bodyPartsDict[leg2Lower].groundContact.touchingGround
? groundedMaterial
: unGroundedMaterial;
foot3.material = m_JdController.bodyPartsDict[leg3Lower].groundContact.touchingGround
? groundedMaterial
: unGroundedMaterial;
}
var cubeForward = m_OrientationCube.transform.forward;
// Set reward for this step according to mixture of the following elements.
// a. Match target speed
//This reward will approach 1 if it matches perfectly and approach zero as it deviates
var matchSpeedReward = GetMatchingVelocityReward(cubeForward * TargetWalkingSpeed, GetAvgVelocity());
// b. Rotation alignment with target direction.
//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);
// var dontLayDownReward = (Vector3.Dot(m_OrientationCube.transform.up, body.up) + 1) * .5F;
var dontLayDownReward = Vector3.Dot(m_OrientationCube.transform.up, body.up);
AddReward(matchSpeedReward * lookAtTargetReward * dontLayDownReward);
}
/// <summary>
/// Update OrientationCube and DirectionIndicator
/// </summary>
void UpdateOrientationObjects()
{
m_OrientationCube.UpdateOrientation(body, m_Target);
if (m_DirectionIndicator)
{
m_DirectionIndicator.MatchOrientation(m_OrientationCube.transform);
}
}
/// <summary>
///Returns the average velocity of all of the body parts
///Using the velocity of the body only has shown to result in more erratic movement from the limbs
///Using the average helps prevent this erratic movement
/// </summary>
Vector3 GetAvgVelocity()
{
Vector3 velSum = Vector3.zero;
Vector3 avgVel = Vector3.zero;
//ALL RBS
int numOfRB = 0;
foreach (var item in m_JdController.bodyPartsList)
{
numOfRB++;
velSum += item.rb.velocity;
}
avgVel = velSum / numOfRB;
return avgVel;
}
/// <summary>
/// Normalized value of the difference in actual speed vs goal walking speed.
/// </summary>
public float GetMatchingVelocityReward(Vector3 velocityGoal, Vector3 actualVelocity)
{
//distance between our actual velocity and goal velocity
var velDeltaMagnitude = Mathf.Clamp(Vector3.Distance(actualVelocity, velocityGoal), 0, TargetWalkingSpeed);
//return the value on a declining sigmoid shaped curve that decays from 1 to 0
//This reward will approach 1 if it matches perfectly and approach zero as it deviates
return Mathf.Pow(1 - Mathf.Pow(velDeltaMagnitude / TargetWalkingSpeed, 2), 2);
}
/// <summary>
/// Agent touched the target
/// </summary>
public void TouchedTarget()
{
AddReward(1f);
}
}

13
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CreatureAgent.cs.meta


fileFormatVersion: 2
guid: 9f550fc87a87f4a9d9d74e6122ce0f9e
timeCreated: 1525902546
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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

11
Project/Assets/ML-Agents/Examples/Crawler/TFModels/Creature2Legs.nn.meta


fileFormatVersion: 2
guid: 7da1a25807a734bea87504fb16fa01ea
ScriptedImporter:
fileIDToRecycleName:
11400000: main obj
11400002: model data
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 19ed1486aa27d4903b34839f37b8f69f, type: 3}

78
Project/Assets/ML-Agents/Examples/SharedAssets/Materials/MOON.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: MOON
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON _EMISSION _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 0
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 0.21568628}
- _EmissionColor: {r: 0.61503774, g: 0.63782555, b: 0.6981132, a: 1}

8
Project/Assets/ML-Agents/Examples/SharedAssets/Materials/MOON.mat.meta


fileFormatVersion: 2
guid: 9c430da4bdf75438d89106f7f486c83c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

77
Project/Assets/ML-Agents/Examples/SharedAssets/Materials/ProjectileMat.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: ProjectileMat
m_Shader: {fileID: 10755, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _EMISSION _GLOSSYREFLECTIONS_OFF
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 0.9258982, b: 0, a: 1}
- _EmissionColor: {r: 1, g: 0.6018832, b: 0, a: 1}

10
Project/Assets/ML-Agents/Examples/SharedAssets/Materials/ProjectileMat.mat.meta


fileFormatVersion: 2
guid: b619b5e5be0fb4c5bb27daeccc4035c4
timeCreated: 1513128297
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

78
Project/Assets/ML-Agents/Examples/SharedAssets/Materials/WhiteEmissive.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: WhiteEmissive
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON _EMISSION _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 0
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 0.21568628}
- _EmissionColor: {r: 0.49056602, g: 0.49056602, b: 0.49056602, a: 1}

8
Project/Assets/ML-Agents/Examples/SharedAssets/Materials/WhiteEmissive.mat.meta


fileFormatVersion: 2
guid: b0c79355837b24c03a76733e3629163d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

634
Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/PlayerCubeWithGun.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2170513383024431815
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513383024431812}
- component: {fileID: 2170513383024431810}
- component: {fileID: 2170513383024431813}
m_Layer: 0
m_Name: eye
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2170513383024431812
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383024431815}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0}
m_LocalPosition: {x: 0.29999995, y: 0.07399994, z: 0.50040054}
m_LocalScale: {x: 0.29457998, y: 0.29457998, z: 0.29457998}
m_Children: []
m_Father: {fileID: 2170513383808163269}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!33 &2170513383024431810
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383024431815}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &2170513383024431813
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383024431815}
m_Enabled: 1
m_CastShadows: 1
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: f731be6866ce749fd8349e67ae81f76a, 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!1 &2170513383347468444
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513383347468445}
- component: {fileID: 2170513383347468443}
- component: {fileID: 2170513383347468442}
m_Layer: 0
m_Name: mouth
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2170513383347468445
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383347468444}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0}
m_LocalPosition: {x: 0, y: -0.18299997, z: 0.50040054}
m_LocalScale: {x: 0.27602, y: 0.042489994, z: 0.13891}
m_Children: []
m_Father: {fileID: 2170513383808163269}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!33 &2170513383347468443
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383347468444}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &2170513383347468442
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383347468444}
m_Enabled: 1
m_CastShadows: 1
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: f731be6866ce749fd8349e67ae81f76a, 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!1 &2170513383808163268
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513383808163269}
- component: {fileID: 2170513383808163267}
- component: {fileID: 2170513383808163266}
m_Layer: 0
m_Name: AgentCube_Blue
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2170513383808163269
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383808163268}
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: 2170513384853870151}
- {fileID: 2170513383024431812}
- {fileID: 2170513384254877933}
- {fileID: 2170513383347468445}
- {fileID: 2170513384182965506}
m_Father: {fileID: 2170513384791859414}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &2170513383808163267
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383808163268}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &2170513383808163266
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513383808163268}
m_Enabled: 1
m_CastShadows: 1
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: c9fa44c2c3f8ce74ca39a3355ea42631, 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!1 &2170513384182965509
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513384182965506}
- component: {fileID: 2170513384182965504}
- component: {fileID: 2170513384182965507}
m_Layer: 0
m_Name: Headband
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2170513384182965506
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384182965509}
m_LocalRotation: {x: -0, y: -0, z: 0.016506119, w: 0.9998638}
m_LocalPosition: {x: 0, y: 0.341, z: 0}
m_LocalScale: {x: 1.0441425, y: 0.19278127, z: 1.0441422}
m_Children: []
m_Father: {fileID: 2170513383808163269}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: -179.99998, z: 1.8920001}
--- !u!33 &2170513384182965504
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384182965509}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &2170513384182965507
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384182965509}
m_Enabled: 1
m_CastShadows: 1
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: 04be259c590de46f69db4cbd1da877d5, 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!1 &2170513384254877932
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513384254877933}
- component: {fileID: 2170513384254877931}
- component: {fileID: 2170513384254877930}
m_Layer: 0
m_Name: eye
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2170513384254877933
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384254877932}
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0}
m_LocalPosition: {x: -0.29999995, y: 0.07399994, z: 0.50040054}
m_LocalScale: {x: 0.29457998, y: 0.29457998, z: 0.29457998}
m_Children: []
m_Father: {fileID: 2170513383808163269}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!33 &2170513384254877931
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384254877932}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &2170513384254877930
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384254877932}
m_Enabled: 1
m_CastShadows: 1
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: f731be6866ce749fd8349e67ae81f76a, 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!1 &2170513384717669919
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513384717669916}
- component: {fileID: 2170513384717669917}
m_Layer: 0
m_Name: GUN
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2170513384717669916
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384717669919}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 1.02}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2170513384791859414}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2170513384717669917
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384717669919}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 975a5260e89274437b77fd60ca9c1ed1, type: 3}
m_Name:
m_EditorClassIdentifier:
initialized: 0
projectilePrefab: {fileID: 3911029810215854908, guid: 01e75f85d5a3c451b9a5bed7070be0a0,
type: 3}
numberOfProjectilesToPool: 25
projectileStartingPos: {fileID: 2170513384717669916}
projectileLaunchAngle: 5
shootingRate: 0.02
coolDownWait: 0
autoShootEnabled: 0
autoShootDistance: 33
useStandaloneInput: 0
shootKey: 106
--- !u!1 &2170513384791859417
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513384791859414}
- component: {fileID: 2170513384791859413}
- component: {fileID: 2170513384791859412}
- component: {fileID: 2170513384791859415}
- component: {fileID: 2170513384791859410}
m_Layer: 0
m_Name: PlayerCubeWithGun
m_TagString: agent
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2170513384791859414
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384791859417}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 1, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2170513383808163269}
- {fileID: 2170513384717669916}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}
--- !u!54 &2170513384791859413
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384791859417}
serializedVersion: 2
m_Mass: 3
m_Drag: 0.05
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 3
--- !u!65 &2170513384791859412
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384791859417}
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 &2170513384791859415
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384791859417}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eda0377c523784b2e979b7d192b272d7, type: 3}
m_Name:
m_EditorClassIdentifier:
maxAngularVel: 50
runningForceMode: 2
agentRunSpeed: 10
agentTerminalVel: 20
agentRunInAirSpeed: 7
dashBoostForce: 20
dashForceMode: 1
dashPressed: 0
agentIdleDragVelCoeff: 0.9
groundPoundForceMode: 2
groundPoundForce: 35
spinAttackSpeed: 20
agentRotationSpeed: 35
agentJumpVelocity: 25
agentFallingSpeed: 50
--- !u!114 &2170513384791859410
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384791859417}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 491a09f8a027b44ce87fc4c37f18547f, type: 3}
m_Name:
m_EditorClassIdentifier:
debugDrawGizmos: 0
hitGroundColliders:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
groundCheckBoxLocalPos: {x: 0, y: -0.52, z: 0}
groundCheckBoxSize: {x: 0.99, y: 0.1, z: 0.99}
isGrounded: 0
ungroundedTime: 0
groundedTime: 0
--- !u!1 &2170513384853870150
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2170513384853870151}
- component: {fileID: 2170513384853870148}
m_Layer: 0
m_Name: AgentCamera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &2170513384853870151
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384853870150}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.15}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2170513383808163269}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &2170513384853870148
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2170513384853870150}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.46666667, g: 0.5647059, b: 0.60784316, a: 1}
m_projectionMatrixMode: 1
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294950911
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022

7
Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/PlayerCubeWithGun.prefab.meta


fileFormatVersion: 2
guid: 497c5a1fa56ff4204a66acfb42a8ebde
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

129
Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/Projectile.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3911029810215854908
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3911029810215854904}
- component: {fileID: 3911029810215854911}
- component: {fileID: 3911029810215854910}
- component: {fileID: 3911029810215854909}
- component: {fileID: 648473049}
- component: {fileID: 4341296992446652170}
m_Layer: 0
m_Name: Projectile
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3911029810215854904
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3911029810215854908}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 2.8, z: 0}
m_LocalScale: {x: 0.4, y: 0.4, z: 0.4}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &3911029810215854911
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3911029810215854908}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &3911029810215854910
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3911029810215854908}
m_Enabled: 1
m_CastShadows: 1
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: b619b5e5be0fb4c5bb27daeccc4035c4, 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: 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 &3911029810215854909
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3911029810215854908}
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 &648473049
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3911029810215854908}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 675ac467ea9374f16a31f2849d2cc769, type: 3}
m_Name:
m_EditorClassIdentifier:
aliveTime: 0
rb: {fileID: 0}
selfDestructNow: 0
maxTimeToLive: 3
pauseCollisionDetectionWaitTime: 0.1
projectileController: {fileID: 0}
--- !u!54 &4341296992446652170
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3911029810215854908}
serializedVersion: 2
m_Mass: 10
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 3

7
Project/Assets/ML-Agents/Examples/SharedAssets/Prefabs/Projectile.prefab.meta


fileFormatVersion: 2
guid: 01e75f85d5a3c451b9a5bed7070be0a0
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

81
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AgentCubeGroundCheck.cs


//Standardized ground check for the Agent Cube
using UnityEngine;
namespace MLAgents
{
/// <summary>
/// Perform Groundcheck using a Physics OverlapBox
/// </summary>
[DisallowMultipleComponent]
public class AgentCubeGroundCheck : MonoBehaviour
{
public bool debugDrawGizmos;
public Collider[] hitGroundColliders = new Collider[3];
public Vector3 groundCheckBoxLocalPos = new Vector3(0, -0.52f, 0);
public Vector3 groundCheckBoxSize = new Vector3(0.99f, 0.02f, 0.99f);
public bool isGrounded;
public float ungroundedTime; //amount of time agent hasn't been grounded
public float groundedTime; //amount of time agent has been grounded
void FixedUpdate()
{
DoGroundCheck();
if (!isGrounded)
{
ungroundedTime += Time.deltaTime;
groundedTime = 0;
}
else
{
groundedTime += Time.deltaTime;
ungroundedTime = 0;
}
}
/// <summary>
/// Does the ground check.
/// </summary>
/// <returns><c>true</c>, if the agent is on the ground,
/// <c>false</c> otherwise.</returns>
/// <param name="smallCheck"></param>
public void DoGroundCheck()
{
isGrounded = false;
if (Physics.OverlapBoxNonAlloc(
transform.TransformPoint(groundCheckBoxLocalPos),
groundCheckBoxSize / 2,
hitGroundColliders,
transform.rotation) > 0)
{
foreach (var col in hitGroundColliders)
{
if (col != null && col.transform != transform &&
(col.CompareTag("walkableSurface")
|| col.CompareTag("ground")
|| col.CompareTag("block")))
{
isGrounded = true; //then we're grounded
break;
}
}
}
//empty the array
for (int i = 0; i < hitGroundColliders.Length; i++)
{
hitGroundColliders[i] = null;
}
}
//Draw the Box Overlap as a gizmo to show where it currently is testing.
void OnDrawGizmos()
{
if (debugDrawGizmos)
{
Gizmos.color = Color.red;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(groundCheckBoxLocalPos, groundCheckBoxSize);
}
}
}
}

11
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AgentCubeGroundCheck.cs.meta


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

355
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AvgCenterOfMass.cs


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
{
[System.Serializable]
public class ShiftCom
{
public Rigidbody rb;
public Vector3 shiftComAmount;
}
/// <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 active;
public bool showCOMGizmos = true;
public Vector3 avgCOMWorldSpace;
public Vector3 avgCOMVelocityWorldSpace;
public Vector3 previousAvgCOM;
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;
[Tooltip("ShiftCom")] public bool updateShiftCom;
public List<ShiftCom> shiftComList = new List<ShiftCom>();
void OnEnable()
{
SetUpRigidbodies();
}
void SetUpRigidbodies()
{
rbList.Clear();
totalMass = 0;
foreach (var item in GetComponentsInChildren<Rigidbody>())
{
rbList.Add(item);
totalMass += item.mass;
}
foreach (var item in shiftComList)
{
item.rb.centerOfMass = item.shiftComAmount;
}
}
// 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
// }
// }
public Vector3 GetCoMWorldSpace()
{
Vector3 CoM = Vector3.zero;
avgCOMWorldSpace = Vector3.zero;
float c = 0f;
foreach (var item in rbList)
{
CoM += item.worldCenterOfMass * item.mass;
c += item.mass;
}
avgCOMWorldSpace = CoM / c;
avgCOMVelocityWorldSpace = (avgCOMWorldSpace - previousAvgCOM) / Time.fixedDeltaTime;
// Debug.DrawRay(avgCOMWorldSpace, avgCOMVelocityWorldSpace, Color.green,Time.fixedDeltaTime);
// Debug.DrawRay(avgCOMWorldSpace, Vector3.ProjectOnPlane( avgCOMVelocityWorldSpace, Vector3.up), Color.green,Time.fixedDeltaTime);
previousAvgCOM = avgCOMWorldSpace;
return avgCOMWorldSpace;
}
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
// if (active)
// {
GetCoMWorldSpace();
// }
// Vector3 CoM = Vector3.zero;
// avgCOMWorldSpace = Vector3.zero;
// float c = 0f;
//
// foreach(var item in rbList)
// {
// CoM += item.worldCenterOfMass * item.mass;
// c += item.mass;
// }
// avgCOMWorldSpace = CoM/c;
// avgCOMVelocityWorldSpace = previousAvgCOM - avgCOMWorldSpace;
// Debug.DrawRay(avgCOMWorldSpace, avgCOMVelocityWorldSpace, Color.green,Time.fixedDeltaTime);
//
// previousAvgCOM = avgCOMWorldSpace;
// // 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()
private void OnDrawGizmos()
{
if (updateShiftCom)
{
foreach (var item in shiftComList)
{
item.rb.centerOfMass = item.shiftComAmount;
}
updateShiftCom = false;
}
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.5f; //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.5f; //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);
// }
// }
// }
}

11
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AvgCenterOfMass.cs.meta


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

84
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Projectile.cs


using UnityEngine;
//This script handles the logic to determine whether an active projectile
//...should be remain active after it has been shot by an enemy
public class Projectile : MonoBehaviour
{
public float aliveTime;
[HideInInspector] public Rigidbody rb;
// private ObstacleTowerAgent agent;
public bool selfDestructNow;
public float maxTimeToLive = 3;
public float pauseCollisionDetectionWaitTime = .5f;
[HideInInspector] public ShootProjectiles projectileController;
void Awake()
{
rb = GetComponent<Rigidbody>();
// agent = FindObjectOfType<ObstacleTowerAgent>();
}
void OnEnable()
{
if (!rb)
{
rb = GetComponent<Rigidbody>();
}
aliveTime = 0;
selfDestructNow = false;
// if (agent)
// {
// agent.CompletedFloorAction += SelfDestruct;
// }
}
void OnDisable()
{
aliveTime = 0;
// if (agent)
// {
// agent.CompletedFloorAction -= SelfDestruct;
// }
}
//Turn the projectile off
void SelfDestruct()
{
gameObject.SetActive(false);
// rb.velocity = Vector3.zero;
// rb.angularVelocity = Vector3.zero;
}
void FixedUpdate()
{
// if (
// (agent && agent.IsDone()) //if the agent is done projectiles can die
// || aliveTime > maxTimeToLive //we lived too long. time to die
// )
if (aliveTime > maxTimeToLive) //we lived too long. time to die
{
selfDestructNow = true;
}
if (selfDestructNow)
{
SelfDestruct();
}
aliveTime += Time.fixedDeltaTime;
}
void OnCollisionEnter()
{
if (aliveTime > pauseCollisionDetectionWaitTime)
{
selfDestructNow = true;
}
}
}

11
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Projectile.cs.meta


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

142
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ShootProjectiles.cs


using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Logic for robot projectiles.
/// </summary>
public class ShootProjectiles : MonoBehaviour
{
public bool initialized; //has this robot been initialized
public GameObject projectilePrefab;
public int numberOfProjectilesToPool = 12;
private List<Projectile> projectilePoolList = new List<Projectile>(); //projectiles to shoot
public Transform projectileStartingPos; //the transform the projectile will originate from
public float projectileLaunchAngle = 25; //the angle at which the projectile will launch
public float shootingRate = .5f; //can shoot every shootingRate seconds. ex: .5 can shoot every .5 seconds
private float shootTimer;
public bool coolDownWait;
//for standalone projectiles
public bool autoShootEnabled;
public float autoShootDistance = 4;
public bool useStandaloneInput = false;
public KeyCode shootKey = KeyCode.Space;
void Start()
{
if (!initialized)
{
Initialize();
}
}
void OnEnable()
{
if (!initialized)
{
Initialize();
}
}
void Initialize()
{
projectilePoolList.Clear(); //clear list in case it's not empty
for (var i = 0; i < numberOfProjectilesToPool; i++)
{
GameObject obj = Instantiate(projectilePrefab, transform.position, Quaternion.identity);
Projectile p = obj.GetComponent<Projectile>();
projectilePoolList.Add(p);
p.transform.position = projectileStartingPos.position;
p.projectileController = this;
p.gameObject.SetActive(false);
}
initialized = true;
}
void Update()
{
if (Input.GetKey(shootKey))
{
Shoot(projectileStartingPos.position,
projectileStartingPos.TransformPoint(Vector3.forward * autoShootDistance));
}
}
void FixedUpdate()
{
coolDownWait = shootTimer > shootingRate ? false : true;
shootTimer += Time.fixedDeltaTime;
if (autoShootEnabled)
{
Shoot(projectileStartingPos.position,
projectileStartingPos.TransformPoint(Vector3.forward * autoShootDistance));
Debug.DrawRay(projectileStartingPos.TransformPoint(Vector3.forward * autoShootDistance), Vector3.up);
}
}
public void Shoot(Vector3 startPos, Vector3 targetPos)
{
if (coolDownWait)
{
return;
}
shootTimer = 0; //reset timer
//shoot first available projectile in the pool
foreach (var item in projectilePoolList)
{
if (!item.gameObject.activeInHierarchy)
{
LaunchProjectile(item.rb, startPos, targetPos); //shoot
break;
}
}
}
public void LaunchProjectile(Rigidbody rb, Vector3 startPos, Vector3 targetPos)
{
rb.transform.position = startPos;
rb.transform.rotation = Quaternion.identity;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
rb.gameObject.SetActive(true);
Vector3 p = targetPos;
float gravity = Physics.gravity.magnitude;
// Selected angle in radians
float angle = projectileLaunchAngle * Mathf.Deg2Rad;
// Positions of this object and the target on the same plane
Vector3 planarTarget = new Vector3(p.x, 0, p.z);
Vector3 planarPostion = new Vector3(startPos.x, 0, startPos.z);
// Planar distance between objects
float distance = Vector3.Distance(planarTarget, planarPostion);
// Distance along the y axis between objects
float yOffset = startPos.y - p.y;
float initialVelocity = (1 / Mathf.Cos(angle)) *
Mathf.Sqrt((0.5f * gravity * Mathf.Pow(distance, 2)) /
(distance * Mathf.Tan(angle) + yOffset));
Vector3 velocity = new Vector3(0, initialVelocity * Mathf.Sin(angle), initialVelocity * Mathf.Cos(angle));
// Rotate our velocity to match the direction between the two objects
float angleBetweenObjects =
Vector3.Angle(Vector3.forward, planarTarget - planarPostion) * (p.x > startPos.x ? 1 : -1);
Vector3 finalVelocity = Quaternion.AngleAxis(angleBetweenObjects, Vector3.up) * velocity;
if (!float.IsNaN(finalVelocity.x)) //NaN checked
{
rb.velocity = finalVelocity;
}
}
}

11
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ShootProjectiles.cs.meta


fileFormatVersion: 2
guid: 975a5260e89274437b77fd60ca9c1ed1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存