浏览代码

add simple training scene

/develop/dodgeball-tests
HH 4 年前
当前提交
1f8aa5c3
共有 9 个文件被更改,包括 152 次插入191 次删除
  1. 210
      Project/Assets/ML-Agents/Examples/Dodgeball/Prefabs/DodgeballAgent.prefab
  2. 8
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallAgent.cs
  3. 7
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallGameController.cs
  4. 12
      Project/ProjectSettings/DynamicsManager.asset
  5. 4
      Project/ProjectSettings/TimeManager.asset
  6. 2
      config/ppo/DodgeBall.yaml
  7. 89
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallPlatform.cs
  8. 11
      Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallPlatform.cs.meta

210
Project/Assets/ML-Agents/Examples/Dodgeball/Prefabs/DodgeballAgent.prefab


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

- component: {fileID: 6859136915777268217}
- component: {fileID: 2592381937844435691}
- component: {fileID: 5437457129861593600}
- component: {fileID: 3533182982885445785}
m_Layer: 10
m_Name: Sphere
m_TagString: Untagged

m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &3533182982885445785
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3293956224856936763}
m_Material: {fileID: 13400000, guid: a40529e7c808a457584d7f20faab7c88, type: 2}
m_IsTrigger: 0
m_Enabled: 0
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &3293956225661193221
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 6859136916585723079}
- component: {fileID: 2592381937572849621}
- component: {fileID: 5437457129590007614}
- component: {fileID: 3533182983687605671}
m_Layer: 10
m_Name: Sphere
m_TagString: Untagged

m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &3533182983687605671
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3293956225661193221}
m_Material: {fileID: 13400000, guid: a40529e7c808a457584d7f20faab7c88, type: 2}
m_IsTrigger: 0
m_Enabled: 0
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &3293956225952600861
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 6859136916864084959}
- component: {fileID: 2592381938904119501}
- component: {fileID: 5437457128791947302}
- component: {fileID: 3533182983945589439}
m_Layer: 10
m_Name: Sphere
m_TagString: Untagged

m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &3533182983945589439
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3293956225952600861}
m_Material: {fileID: 13400000, guid: a40529e7c808a457584d7f20faab7c88, type: 2}
m_IsTrigger: 0
m_Enabled: 0
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &4781571356481907573
GameObject:
m_ObjectHideFlags: 0

serializedVersion: 6
m_Component:
- component: {fileID: 4781571356481907569}
- component: {fileID: 5197764927471310659}
m_Layer: 10
m_Name: Projectile - BALL 3
m_TagString: dodgeBall

m_Father: {fileID: 7249994047908302975}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: -90.00001, z: 0}
--- !u!54 &5197764927471310659
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4781571356481907573}
serializedVersion: 2
m_Mass: 0.5
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 3
--- !u!1 &4781571357543950675
GameObject:
m_ObjectHideFlags: 0

serializedVersion: 6
m_Component:
- component: {fileID: 4781571357543950679}
- component: {fileID: 5197764928516576613}
m_Layer: 10
m_Name: Projectile - BALL 4
m_TagString: dodgeBall

m_Father: {fileID: 7249994047908302975}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: -90.00001, z: 0}
--- !u!54 &5197764928516576613
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4781571357543950675}
serializedVersion: 2
m_Mass: 0.5
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 3
--- !u!1 &4781571357817631853
GameObject:
m_ObjectHideFlags: 0

serializedVersion: 6
m_Component:
- component: {fileID: 4781571357817631849}
- component: {fileID: 5197764928786057307}
m_Layer: 10
m_Name: Projectile - BALL 2
m_TagString: dodgeBall

m_Father: {fileID: 7249994047908302975}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: -90.00001, z: 0}
--- !u!54 &5197764928786057307
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4781571357817631853}
serializedVersion: 2
m_Mass: 0.5
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 3
--- !u!108 &3257459467654749876
Light:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
VectorObservationSize: 2
VectorObservationSize: 5
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 5

agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
MaxStep: 0
MaxStep: 3000
teamID: 0
ThrowController: {fileID: 8366924173413481317}
AgentHealth: {fileID: 0}

serializedVersion: 6
m_Component:
- component: {fileID: 8366924173413481312}
- component: {fileID: 8366924173413481316}
- component: {fileID: 8366924173413481317}
- component: {fileID: 8366924173413481314}
- component: {fileID: 8366924173413481313}

m_Father: {fileID: 6960991001359725254}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: -1, y: 0, z: 0}
--- !u!114 &8366924173413481316
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8366924173413481311}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f25a3868f6567418d8fca3276794e44a, type: 3}
m_Name:
m_EditorClassIdentifier:
initialized: 0
projectilePrefab: {fileID: 3911029810215854908, guid: 01e75f85d5a3c451b9a5bed7070be0a0,
type: 3}
numberOfProjectilesToPool: 25
projectileStartingPos: {fileID: 8366924173548761677}
projectileLaunchAngle: 5
shootingRate: 0.02
coolDownWait: 0
autoShootEnabled: 0
autoShootDistance: 30
useStandaloneInput: 0
shootKey: 106
--- !u!114 &8366924173413481317
MonoBehaviour:
m_ObjectHideFlags: 0

initialized: 0
shootKey: 106
autoShootEnabled: 0
shootingRate: 0.02
shootingRate: 0.25
coolDownTimer: 0
coolDownWait: 0
projectilePrefab: {fileID: 3911029810215854908, guid: 4c3111f00dcbe425186833fe890fcac7,
type: 3}

- component: {fileID: 8366924173958317520}
- component: {fileID: 8366924173958317523}
- component: {fileID: 8366924173958317522}
- component: {fileID: 8366924173958317521}
m_Layer: 10
m_Name: Sphere
m_TagString: Untagged

m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &8366924173958317521
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8366924173958317519}
m_Material: {fileID: 13400000, guid: a40529e7c808a457584d7f20faab7c88, type: 2}
m_IsTrigger: 0
m_Enabled: 0
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &8366924174067774693
GameObject:
m_ObjectHideFlags: 0

m_Bits: 2049
gridDepthType: 1
rootReference: {fileID: 8366924174162893207}
MaxColliderBufferSize: 500
InitialColliderBufferSize: 4
ObservationPerCell: 6
NumberOfObservations: 9600
ChannelOffsets: 00000000

serializedVersion: 6
m_Component:
- component: {fileID: 8366924174548624240}
- component: {fileID: 8366924174548624241}
m_Layer: 10
m_Name: Projectile - BALL 1
m_TagString: dodgeBall

m_Father: {fileID: 7249994047908302975}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: -90.00001, z: 0}
--- !u!54 &8366924174548624241
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8366924174548624239}
serializedVersion: 2
m_Mass: 0.5
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 3
--- !u!1 &8366924174593338015
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9116796388679672958}
m_LocalRotation: {x: 0.023514416, y: 3.1894046e-10, z: -7.5017536e-12, w: 0.9997235}
m_LocalRotation: {x: 0.023514433, y: -0.0000000052765476, z: 1.2410933e-10, w: 0.9997235}
m_LocalPosition: {x: 0, y: 1.9999999, z: -5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1b24fe96fd75b4646a6e7bf65b6a4943, type: 3}
--- !u!1 &6009346782108972195 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1158006594261827975, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 4861475078010090788}
m_PrefabAsset: {fileID: 0}
type: 3}
m_PrefabInstance: {fileID: 4861475078010090788}
m_PrefabAsset: {fileID: 0}
--- !u!1 &6009346782108972195 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1158006594261827975, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 4861475078010090788}
m_PrefabAsset: {fileID: 0}

objectReference: {fileID: 2100000, guid: cb2aa8892bed247b58476624d7896b0f, type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1b24fe96fd75b4646a6e7bf65b6a4943, type: 3}
--- !u!4 &2533523931698112273 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6284117573631589716, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924173863852613}
m_PrefabAsset: {fileID: 0}
--- !u!1 &7210080383545760706 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1158006594261827975, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,

--- !u!4 &2533523931698112273 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6284117573631589716, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924173863852613}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &8366924173884781751
PrefabInstance:
m_ObjectHideFlags: 0

objectReference: {fileID: 2100000, guid: cb2aa8892bed247b58476624d7896b0f, type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1b24fe96fd75b4646a6e7bf65b6a4943, type: 3}
--- !u!4 &2533523931652835811 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6284117573631589716, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924173884781751}
m_PrefabAsset: {fileID: 0}
type: 3}
m_PrefabInstance: {fileID: 8366924173884781751}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2533523931652835811 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6284117573631589716, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924173884781751}
m_PrefabAsset: {fileID: 0}

objectReference: {fileID: 2100000, guid: cb2aa8892bed247b58476624d7896b0f, type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1b24fe96fd75b4646a6e7bf65b6a4943, type: 3}
--- !u!1 &7210080382734939128 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1158006594261827975, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924174645850751}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2533523930904088363 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 6284117573631589716, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,

--- !u!1 &7210080382734939128 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1158006594261827975, guid: 1b24fe96fd75b4646a6e7bf65b6a4943,
type: 3}
m_PrefabInstance: {fileID: 8366924174645850751}
m_PrefabAsset: {fileID: 0}

8
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallAgent.cs


// m_Cam = Camera.main;
m_AgentRb = GetComponent<Rigidbody>();
input = GetComponent<DodgeBallAgentInput>();
m_GameController = FindObjectOfType<DodgeBallGameController>();
m_GameController = GetComponentInParent<DodgeBallGameController>();
m_StartingPos = transform.position;
m_StartingRot = transform.rotation;
m_Initialized = true;

sensor.AddObservation(ThrowController.coolDownWait); //Held DBs Normalized
sensor.AddObservation((float)currentNumberOfBalls/4); //Held DBs Normalized
sensor.AddObservation((float)HitPointsRemaining/(float)NumberOfTimesPlayerCanBeHit); //Remaining Hit Points Normalized
// // var localVelocity = transform.InverseTransformDirection(m_AgentRb.velocity);
sensor.AddObservation(Vector3.Dot(m_AgentRb.velocity, m_AgentRb.transform.forward));
sensor.AddObservation(Vector3.Dot(m_AgentRb.velocity, m_AgentRb.transform.right));
// sensor.AddObservation(Vector3.Dot(m_AgentRb.angularVelocity, m_AgentRb.transform.forward));
// sensor.AddObservation(Vector3.Dot(m_AgentRb.velocity, m_AgentRb.transform.right));
// // var localVelocity = transform.InverseTransformDirection(m_AgentRb.velocity);
// // sensor.AddObservation(localVelocity.x);
// // sensor.AddObservation(localVelocity.z);
// // sensor.AddObservation(m_Frozen);

7
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallGameController.cs


// public List<DodgeBall> currentlyHeldBalls;
// }
[Serializable]
public class AgentInfo
{

var HitByTeamList = hitTeamID == 1 ? Team0Players : Team1Players;
// int hitByTeamID = hitTeamID == 0? 1: 0; //assumes only 2 teams
HitByTeamList[0].Agent.AddReward(1);
if (info.HitPointsRemaining == 1)
{
//RESET ENV

// agent.AddReward(-1f); //you lost penalty
HitByTeamList[0].Agent.AddReward(1);
if (info.TeamID == 0)
{
print($"Team 1 Won");

info.HitPointsRemaining--;
//ASSIGN REWARDS
// agent.AddReward(-.1f); //small hit penalty
HitByTeamList[0].Agent.AddReward(.1f);
// HitByTeamList[0].Agent.AddReward(.1f);
}
// ResetScene();

{
m_ResetTimer = 0;
print($"Resetting {gameObject.name}");
//Reset Balls
foreach (var item in AllBallsList)
{

12
Project/ProjectSettings/DynamicsManager.asset


m_BounceThreshold: 2
m_SleepThreshold: 0.005
m_DefaultContactOffset: 0.01
m_DefaultSolverIterations: 12
m_DefaultSolverVelocityIterations: 12
m_DefaultSolverIterations: 6
m_DefaultSolverVelocityIterations: 1
m_QueriesHitTriggers: 1
m_QueriesHitTriggers: 0
m_EnableAdaptiveForce: 0
m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0

m_ClothInterCollisionSettingsToggle: 0
m_ClothGravity: {x: 0, y: -9.81, z: 0}
m_ContactPairsMode: 0
m_BroadphaseType: 0
m_BroadphaseType: 2
m_WorldBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 250, y: 250, z: 250}

m_EnableUnifiedHeightmaps: 1
m_SolverType: 0
m_EnableUnifiedHeightmaps: 0
m_SolverType: 1
m_DefaultMaxAngularSpeed: 25

4
Project/ProjectSettings/TimeManager.asset


--- !u!5 &1
TimeManager:
m_ObjectHideFlags: 0
Fixed Timestep: 0.02
Maximum Allowed Timestep: 0.33333334
Fixed Timestep: 0.01333
Maximum Allowed Timestep: 0.15
m_TimeScale: 1
Maximum Particle Timestep: 0.03

2
config/ppo/DodgeBall.yaml


keep_checkpoints: 5
max_steps: 2000000
time_horizon: 64
summary_freq: 60000
summary_freq: 5000
threaded: true

89
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallPlatform.cs


// using System.Collections;
// using System.Collections.Generic;
// using UnityEngine;
//
// public class DodgeBallPlatform : MonoBehaviour
// {
//
// [Header("BALLS")] public GameObject BallPrefab;
// public float BallSpawnRadius = 3;
// public Transform BallSpawnPosition;
// public int NumberOfBallsToSpawn = 10;
//
// // Start is called before the first frame update
// void Start()
// {
//
// }
//
// void Initialize()
// {
//
// //SPAWN DODGE BALLS
// for (int i = 0; i < NumberOfBallsToSpawn; i++)
// {
// GameObject g = Instantiate(BallPrefab, BallSpawnPosition.position + Random.insideUnitSphere * BallSpawnRadius,
// Quaternion.identity);
// DodgeBall db = g.GetComponent<DodgeBall>();
// AllBallsList.Add(db);
// g.SetActive(true);
// }
//
// //INITIALIZE AGENTS
// foreach (var item in Team0Players)
// {
// item.Agent.Initialize();
// item.HitPointsRemaining = PlayerMaxHitPoints;
// item.Agent.m_BehaviorParameters.TeamId = 0;
// item.TeamID = 0;
// PlayersDict.Add(item.Agent, item);
// }
// foreach (var item in Team1Players)
// {
// item.Agent.Initialize();
// item.HitPointsRemaining = PlayerMaxHitPoints;
// item.Agent.m_BehaviorParameters.TeamId = 1;
// item.TeamID = 1;
// PlayersDict.Add(item.Agent, item);
// }
//
// m_Initialized = true;
// }
//
// void ResetScene()
// {
// m_ResetTimer = 0;
//
// //Reset Balls
// foreach (var item in AllBallsList)
// {
// item.gameObject.SetActive(true);
// item.transform.position = BallSpawnPosition.position + Random.insideUnitSphere * BallSpawnRadius;
// }
//
// //End Episode
// foreach (var item in Team0Players)
// {
// if (item.Agent.enabled)
// {
// item.Agent.EndEpisode();
// item.HitPointsRemaining = PlayerMaxHitPoints;
// }
// }
// foreach (var item in Team1Players)
// {
// if (item.Agent.enabled)
// {
// item.Agent.EndEpisode();
// item.HitPointsRemaining = PlayerMaxHitPoints;
// }
// }
// // Update is called once per frame
// void Update()
// {
// if (!m_Initialized)
// {
// Initialize();
// }
// }
// }

11
Project/Assets/ML-Agents/Examples/Dodgeball/Scripts/DodgeBallPlatform.cs.meta


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

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存