small AI changes

This commit is contained in:
2024-04-11 14:31:24 +02:00
parent eeb46585e7
commit 83e08fa10d
8 changed files with 166 additions and 88 deletions

8
Assets/Brains.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: acae344fdaa8c094dbeb437aeb9679b3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: c125e980a0ef6a94e9310d21891ba601
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3}
optimizeModel: 1
forceArbitraryBatchSize: 1
treatErrorsAsWarnings: 0
importMode: 1
weightsTypeMode: 0
activationTypeMode: 0

View File

@@ -1 +1 @@
{"count":1,"self":7.2964823999999995,"total":60.9954573,"children":{"InitializeActuators":{"count":3,"self":0.001513,"total":0.001513,"children":null},"InitializeSensors":{"count":3,"self":0.0010095,"total":0.0010095,"children":null},"AgentSendState":{"count":2184,"self":0.0263912,"total":0.1014805,"children":{"CollectObservations":{"count":6552,"self":0.0160938,"total":0.0160938,"children":null},"WriteActionMask":{"count":6552,"self":0.0020112,"total":0.0020112,"children":null},"RequestDecision":{"count":6552,"self":0.019229899999999998,"total":0.056984299999999995,"children":{"AgentInfo.ToProto":{"count":6552,"self":0.016433299999999998,"total":0.0377544,"children":{"GenerateSensorData":{"count":6552,"self":0.0213211,"total":0.0213211,"children":null}}}}}}},"DecideAction":{"count":2184,"self":53.5099136,"total":53.509915199999995,"children":null},"AgentAct":{"count":2184,"self":0.0840575,"total":0.0840575,"children":{"AgentInfo.ToProto":{"count":21,"self":0,"total":0,"children":{"GenerateSensorData":{"count":21,"self":0,"total":0,"children":null}}}}}},"gauges":{"BensonImitationV1.CumulativeReward":{"count":21,"max":0,"min":0,"runningAverage":0,"value":0,"weightedAverage":0}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1712357698","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 61390a08-deee-455b-9b78-7c702050fabf -accessToken HPacrWVInUHR0G5x93m6zxWFWNrjAqy08EExnpTeleY005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"AI training","end_time_seconds":"1712357759"}}
{"count":1,"self":54.6100928,"total":437.0681204,"children":{"InitializeActuators":{"count":1,"self":0.0015050999999999999,"total":0.0015050999999999999,"children":null},"InitializeSensors":{"count":1,"self":0.0010000999999999999,"total":0.0010000999999999999,"children":null},"AgentSendState":{"count":106517,"self":2.4229472,"total":4.9875248,"children":{"CollectObservations":{"count":106517,"self":0.5592851,"total":0.5592851,"children":null},"WriteActionMask":{"count":106517,"self":0.10856139999999999,"total":0.10856139999999999,"children":null},"RequestDecision":{"count":106517,"self":0.3979184,"total":1.8967311,"children":{"AgentInfo.ToProto":{"count":106517,"self":0.41538549999999996,"total":1.4988127,"children":{"GenerateSensorData":{"count":106517,"self":0.93811329999999993,"total":1.0834272,"children":{"RayPerceptionSensor.Perceive":{"count":106517,"self":0.1453139,"total":0.1453139,"children":null}}}}}}}}},"DecideAction":{"count":106517,"self":375.577856,"total":375.5778655,"children":null},"AgentAct":{"count":106517,"self":1.8830943999999998,"total":1.8901329,"children":{"AgentInfo.ToProto":{"count":282,"self":0.0035242999999999997,"total":0.0070383999999999993,"children":{"GenerateSensorData":{"count":282,"self":0.0020112,"total":0.0035141,"children":{"RayPerceptionSensor.Perceive":{"count":282,"self":0.0015029,"total":0.0015029,"children":null}}}}}}}},"gauges":{"BensonImitationV2.CumulativeReward":{"count":282,"max":3.594984,"min":0.06999996,"runningAverage":0.676435947,"value":2.39199162,"weightedAverage":2.00654221}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1712838172","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 6a5e8087-82e2-4dd3-a01c-49b3c989d73e -accessToken rm0_kOgxM-hVgLTEQcJOmvx7-NTfQijYXSBtuUfKLQM005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"AI training","end_time_seconds":"1712838609"}}

View File

@@ -2010,7 +2010,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &4626743643629164319
Transform:
m_ObjectHideFlags: 0
@@ -4167,6 +4167,9 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 5711380006811689493, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
insertIndex: -1
addedObject: {fileID: 8031066805216850976}
- targetCorrespondingSourceObject: {fileID: 5711380006811689493, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
insertIndex: -1
addedObject: {fileID: 6288636727627254098}
m_SourcePrefab: {fileID: 100100000, guid: 5851f609a58dc884a99030da0105c6db, type: 3}
--- !u!1 &4107100509094881531 stripped
GameObject:
@@ -4225,7 +4228,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
VectorObservationSize: 6
VectorObservationSize: 2
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 0
@@ -4272,6 +4275,32 @@ MonoBehaviour:
NumStepsToRecord: 0
DemonstrationName: BensonYouRetard
DemonstrationDirectory:
--- !u!114 &6288636727627254098
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4107100509094881531}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bb6b867a41448888c1cd4f99643ad71, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SensorName: RayPerceptionSensor
m_DetectableTags: []
m_RaysPerDirection: 2
m_MaxRayDegrees: 150
m_SphereCastRadius: 0
m_RayLength: 30
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291
m_ObservationStacks: 1
rayHitColor: {r: 1, g: 0, b: 0, a: 1}
rayMissColor: {r: 1, g: 1, b: 1, a: 1}
m_StartVerticalOffset: 0.5
m_EndVerticalOffset: 1
--- !u!4 &4361687674892069559 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 5420764024659664985, guid: 5851f609a58dc884a99030da0105c6db, type: 3}

View File

@@ -123,6 +123,71 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1001 &96007651
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.x
value: 66.6
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5284110061588260334, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_Name
value: TrainingArea (1)
objectReference: {fileID: 0}
- target: {fileID: 5284110061588260334, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8262033930960634649, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
--- !u!1 &765367128
GameObject:
m_ObjectHideFlags: 0
@@ -140,7 +205,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!81 &765367129
AudioListener:
m_ObjectHideFlags: 0
@@ -209,13 +274,13 @@ Transform:
m_GameObject: {fileID: 765367128}
serializedVersion: 2
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 140, y: 120, z: -40}
m_LocalPosition: {x: 135, y: 170, z: -43}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!1001 &880668635
--- !u!1001 &851810722
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
@@ -225,7 +290,7 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.x
value: 154.5
value: 147.6
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.y
@@ -268,6 +333,10 @@ PrefabInstance:
value: TrainingArea (2)
objectReference: {fileID: 0}
- target: {fileID: 5284110061588260334, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8262033930960634649, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
@@ -380,7 +449,7 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 320316327550477191, guid: 80c5f8bcfe7e033419638b39d9a278c4, type: 3}
propertyPath: m_LocalPosition.x
value: 39.51581
value: 28.615808
objectReference: {fileID: 0}
- target: {fileID: 320316327550477191, guid: 80c5f8bcfe7e033419638b39d9a278c4, type: 3}
propertyPath: m_LocalPosition.y
@@ -428,7 +497,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 1387890555408215438, guid: 80c5f8bcfe7e033419638b39d9a278c4, type: 3}
propertyPath: m_IsActive
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2100622393876020061, guid: 80c5f8bcfe7e033419638b39d9a278c4, type: 3}
propertyPath: CameraSide
@@ -500,7 +569,7 @@ PrefabInstance:
objectReference: {fileID: 1673238739}
- target: {fileID: 8890610309520933432, guid: 80c5f8bcfe7e033419638b39d9a278c4, type: 3}
propertyPath: m_LocalPosition.x
value: 39.51581
value: 28.615808
objectReference: {fileID: 0}
- target: {fileID: 8890610309520933432, guid: 80c5f8bcfe7e033419638b39d9a278c4, type: 3}
propertyPath: m_LocalPosition.y
@@ -544,67 +613,6 @@ Transform:
m_CorrespondingSourceObject: {fileID: 4361687674892069559, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
m_PrefabInstance: {fileID: 3696992500355286030}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1919317728
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.x
value: 71.1
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 494913253421693338, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5284110061588260334, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_Name
value: TrainingArea (1)
objectReference: {fileID: 0}
- target: {fileID: 5284110061588260334, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
--- !u!1 &2015283366 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 4840733166066636179, guid: 80c5f8bcfe7e033419638b39d9a278c4, type: 3}
@@ -674,6 +682,14 @@ PrefabInstance:
propertyPath: m_Name
value: TrainingArea
objectReference: {fileID: 0}
- target: {fileID: 8242215082626919376, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_BehaviorName
value: BensonImitationV2
objectReference: {fileID: 0}
- target: {fileID: 8262033930960634649, guid: 3664a8beed80ac848a9377d9ee14cb9b, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
@@ -687,5 +703,5 @@ SceneRoots:
- {fileID: 1574695326}
- {fileID: 765367131}
- {fileID: 3696992500355286030}
- {fileID: 1919317728}
- {fileID: 880668635}
- {fileID: 851810722}
- {fileID: 96007651}

View File

@@ -9,6 +9,7 @@ using System.Linq;
using Unity.Mathematics;
using Unity.VisualScripting;
using System.Reflection;
using System;
public class AgentController : Agent
{
@@ -41,7 +42,7 @@ public class AgentController : Agent
public override void OnEpisodeBegin()
{
int stepsSinceCheckpoint = 0;
stepsSinceCheckpoint = 0;
// reset wheels
foreach (var wheel in wheels)
{
@@ -79,14 +80,9 @@ public class AgentController : Agent
}
}
sensor.AddObservation(currentCheckpoint.localPosition.x);
sensor.AddObservation(currentCheckpoint.localPosition.z);
float checkpointDistance = distanceToCheckpoint(currentCheckpoint);
// agent
sensor.AddObservation(transform.localPosition.x);
sensor.AddObservation(transform.localPosition.z);
sensor.AddObservation(transform.rotation.eulerAngles.y);
sensor.AddObservation(checkpointDistance);
// Agent velocity
var FullVelocityMagnitude = rigidBody.velocity.magnitude; // Velocity including angular velocity
@@ -130,6 +126,11 @@ public class AgentController : Agent
if (actions.DiscreteActions[1] == 1)
hInput = 1f;
if (vInput == 1f)
{
AddReward(0.001f);
}
float forwardSpeed = Vector3.Dot(transform.forward, rigidBody.velocity);
@@ -210,12 +211,14 @@ public class AgentController : Agent
}
}
var closestPoint = currentCheckpoint.GetComponent<Collider>().ClosestPointOnBounds(transform.localPosition);
var distanceToCheckpoint = Vector3.Distance(transform.localPosition, closestPoint);
float checkpintDistance = distanceToCheckpoint(currentCheckpoint);
if (distanceToCheckpoint < 0.3f)
// float reward = (1 - Mathf.InverseLerp(0, 20, checkpintDistance)) / 1000;
// AddReward(reward);
if (checkpintDistance < 0.1f)
{
Debug.Log(currentCheckpoint.name);
currentCheckpoint.GetComponent<Checkpoint>().isCollected = true;
@@ -223,13 +226,12 @@ public class AgentController : Agent
if (currentCheckpoint == checkpoints[checkpoints.Count - 1].transform)
{
SetReward(10f);
AddReward(10f);
EndEpisode();
Debug.Log("END");
}
SetReward(1.0f);
AddReward(1.0f);
}
currentStep += 1;
@@ -259,4 +261,11 @@ public class AgentController : Agent
if (Input.GetAxis("Horizontal") > 0.5)
discreteActionsOut[1] = 1;
}
float distanceToCheckpoint(Transform checkpoint)
{
var closestPoint = checkpoint.GetComponent<Collider>().ClosestPointOnBounds(transform.position);
var distanceToCheckpoint = Vector3.Distance(transform.position, closestPoint);
return distanceToCheckpoint;
}
}