浏览代码

40 bullet dodge agent

/layernorm
Andrew Cohen 4 年前
当前提交
ff582c7d
共有 3 个文件被更改,包括 29 次插入20 次删除
  1. 19
      Project/Assets/Bullet/Prefabs/BulletArea.prefab
  2. 20
      Project/Assets/Bullet/Scripts/DodgeAgent.cs
  3. 10
      Project/Assets/Bullet/Demos/ExpertPush.demo.meta

19
Project/Assets/Bullet/Prefabs/BulletArea.prefab


- target: {fileID: 2602957484348800521, guid: 16266ae2c040142b1a996878d94ec3fb,
type: 3}
propertyPath: m_BrainParameters.m_ActionSpec.m_NumContinuousActions
value: 2
value: 3
objectReference: {fileID: 0}
- target: {fileID: 2602957484348800521, guid: 16266ae2c040142b1a996878d94ec3fb,
type: 3}

- target: {fileID: 2602957484348800521, guid: 16266ae2c040142b1a996878d94ec3fb,
type: 3}
propertyPath: m_BrainParameters.VectorActionSize.Array.data[0]
value: 2
value: 3
objectReference: {fileID: 0}
- target: {fileID: 2602957484348800521, guid: 16266ae2c040142b1a996878d94ec3fb,
type: 3}
propertyPath: m_BrainParameters.VectorObservationSize
value: 4
objectReference: {fileID: 0}
- target: {fileID: 968348991679639432, guid: 16266ae2c040142b1a996878d94ec3fb,
type: 3}
propertyPath: DecisionPeriod
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5260467540845178092, guid: 16266ae2c040142b1a996878d94ec3fb,
type: 3}
propertyPath: MaxNumObservables
value: 40
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 9204493211719777360, guid: 16266ae2c040142b1a996878d94ec3fb, type: 3}

20
Project/Assets/Bullet/Scripts/DodgeAgent.cs


sensor.AddObservation((transform.position.x - area.transform.position.x) / 10f);
sensor.AddObservation((transform.position.z - area.transform.position.z) / 10f);
sensor.AddObservation(transform.forward.x);
sensor.AddObservation(transform.forward.z);
System.Array.Sort(bullets , (a, b) => (Vector3.Distance(a.transform.position, transform.position)).CompareTo(Vector3.Distance(b.transform.position, transform.position)));
System.Array.Sort(bullets, (a, b) => (Vector3.Distance(a.transform.position, transform.position)).CompareTo(Vector3.Distance(b.transform.position, transform.position)));
int numBulletAdded = 0;
// foreach (Bullet b in bullets)

foreach (Bullet b in bullets)
{
if (numBulletAdded >= 20){
if (numBulletAdded >= 40)
{
break;
}

b.transform.forward.x,
b.transform.forward.z
};
numBulletAdded +=1;
numBulletAdded += 1;
m_BufferSensor.AppendObservation(bulletObservation);

{
var forwardForce = Mathf.Clamp(actionBuffers.ContinuousActions[0], -1f, 1f);
var lateralForce = Mathf.Clamp(actionBuffers.ContinuousActions[1], -1f, 1f);
// var rotationForce = Mathf.Clamp(actionBuffers.ContinuousActions[2], -1f, 1f);
var rotationForce = Mathf.Clamp(actionBuffers.ContinuousActions[2], -1f, 1f);
// Vector3 dirToGo = transform.forward * forwardForce + transform.right * lateralForce;
// Vector3 rotateDir = transform.up * rotationForce;
//Vector3 dirToGo = transform.forward * forwardForce + transform.right * lateralForce;
Vector3 rotateDir = transform.up * rotationForce;
// transform.Rotate(rotateDir, Time.fixedDeltaTime * 200f);
Vector3 dirToGo = new Vector3(1,0,0) * forwardForce + new Vector3(0,0,1)*lateralForce;
transform.Rotate(rotateDir, Time.fixedDeltaTime * 200f);
Vector3 dirToGo = new Vector3(1, 0, 0) * forwardForce + new Vector3(0, 0, 1) * lateralForce;
m_AgentRb.AddForce(dirToGo * m_BulletSettings.agentRunSpeed,
ForceMode.VelocityChange);
//Vector3 dirToCenter = new Vector3((transform.position.x - area.transform.position.x) / 10f, 0f, (transform.position.z - area.transform.position.z) / 10f);

10
Project/Assets/Bullet/Demos/ExpertPush.demo.meta


fileFormatVersion: 2
guid: 991552fb1f89746feb752872053e8fea
ScriptedImporter:
fileIDToRecycleName:
11400000: Assets/ML-Agents/Examples/Bullet/Demos/ExpertPush.demo
externalObjects: {}
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)'
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 7bd65ce151aaa4a41a45312543c56be1, type: 3}
正在加载...
取消
保存