Added respawn for AI, Game manager keeps track of laps

This commit is contained in:
2024-04-24 10:11:56 +02:00
parent f06887db7e
commit 6db70114b0
7 changed files with 369 additions and 1115 deletions

View File

@@ -1758,7 +1758,7 @@ Transform:
m_GameObject: {fileID: 153506}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -926.3537, y: 0, z: 100.35948}
m_LocalPosition: {x: -1439.9213, y: 0, z: 100.35948}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:

View File

@@ -1,9 +1 @@
<<<<<<< HEAD
<<<<<<< HEAD
{"count":1,"self":9.7942816,"total":9.9178692,"children":{"InitializeActuators":{"count":3,"self":0.0020459,"total":0.0020459,"children":null},"InitializeSensors":{"count":3,"self":0.0030012,"total":0.0030012,"children":null},"AgentSendState":{"count":1,"self":0.0055818,"total":0.0235843,"children":{"CollectObservations":{"count":3,"self":0.0020201,"total":0.0020201,"children":null},"WriteActionMask":{"count":3,"self":0,"total":0,"children":null},"RequestDecision":{"count":3,"self":0.0159824,"total":0.0159824,"children":null}}},"DecideAction":{"count":1,"self":0.091910999999999993,"total":0.09295479999999999,"children":{"RayPerceptionSensor.Perceive":{"count":6,"self":0.0010438,"total":0.0010438,"children":null}}},"AgentAct":{"count":1,"self":0.0020017,"total":0.0020017,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713939645","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 985081e8-b814-4bc7-8736-608aea67ce7e -accessToken fMKSu_LeJtSMMwbIluJ0HvaiatLXHDxWic8X4MA6BEQ005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Car Customization","end_time_seconds":"1713939655"}}
=======
{"count":1,"self":107.2838656,"total":107.4925277,"children":{"InitializeActuators":{"count":3,"self":0.0009975,"total":0.0009975,"children":null},"InitializeSensors":{"count":3,"self":0.0025054,"total":0.0025054,"children":null},"AgentSendState":{"count":456,"self":0.011536999999999999,"total":0.026688,"children":{"CollectObservations":{"count":276,"self":0.0020269,"total":0.0020269,"children":null},"WriteActionMask":{"count":276,"self":0,"total":0,"children":null},"RequestDecision":{"count":276,"self":0.0131241,"total":0.0131241,"children":null}}},"DecideAction":{"count":456,"self":0.1577449,"total":0.1597336,"children":{"RayPerceptionSensor.Perceive":{"count":552,"self":0.0019887,"total":0.0019887,"children":null}}},"AgentAct":{"count":456,"self":0.018735099999999998,"total":0.018735099999999998,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713938404","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\Magnus\\Desktop\\UnityStuf\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-Magnus -hubSessionId 8870a2b5-eb85-482c-9f97-a69682ef9b2b -accessToken U1Q6bPAeMgVc12tgfRzGzGVn7bYVzdxATeIOIKVjt3o005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Car Customization","end_time_seconds":"1713938511"}}
>>>>>>> e5ca63e64be4e6649cff2239dddc8b93f8132a10
=======
{"count":1,"self":107.2838656,"total":107.4925277,"children":{"InitializeActuators":{"count":3,"self":0.0009975,"total":0.0009975,"children":null},"InitializeSensors":{"count":3,"self":0.0025054,"total":0.0025054,"children":null},"AgentSendState":{"count":456,"self":0.011536999999999999,"total":0.026688,"children":{"CollectObservations":{"count":276,"self":0.0020269,"total":0.0020269,"children":null},"WriteActionMask":{"count":276,"self":0,"total":0,"children":null},"RequestDecision":{"count":276,"self":0.0131241,"total":0.0131241,"children":null}}},"DecideAction":{"count":456,"self":0.1577449,"total":0.1597336,"children":{"RayPerceptionSensor.Perceive":{"count":552,"self":0.0019887,"total":0.0019887,"children":null}}},"AgentAct":{"count":456,"self":0.018735099999999998,"total":0.018735099999999998,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713938404","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\Magnus\\Desktop\\UnityStuf\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-Magnus -hubSessionId 8870a2b5-eb85-482c-9f97-a69682ef9b2b -accessToken U1Q6bPAeMgVc12tgfRzGzGVn7bYVzdxATeIOIKVjt3o005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Car Customization","end_time_seconds":"1713938511"}}
>>>>>>> 6da99da8c2f8207a43f20c59211df05003d51cb1
{"count":1,"self":86.7022016,"total":87.2017959,"children":{"InitializeActuators":{"count":2,"self":0.0020012999999999997,"total":0.0020012999999999997,"children":null},"InitializeSensors":{"count":2,"self":0.0025069999999999997,"total":0.0025069999999999997,"children":null},"AgentSendState":{"count":2392,"self":0.0591224,"total":0.07723809999999999,"children":{"CollectObservations":{"count":958,"self":0.0045191,"total":0.0045191,"children":null},"WriteActionMask":{"count":958,"self":0.0005076,"total":0.0005076,"children":null},"RequestDecision":{"count":958,"self":0.0095655,"total":0.013089,"children":{"RayPerceptionSensor.Perceive":{"count":958,"self":0.0035234999999999997,"total":0.0035234999999999997,"children":null}}}}},"DecideAction":{"count":2392,"self":0.35492989999999996,"total":0.3589999,"children":{"RayPerceptionSensor.Perceive":{"count":1916,"self":0.00407,"total":0.00407,"children":null}}},"AgentAct":{"count":2392,"self":0.0588493,"total":0.0588493,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713942564","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 985081e8-b814-4bc7-8736-608aea67ce7e -accessToken fMKSu_LeJtSMMwbIluJ0HvaiatLXHDxWic8X4MA6BEQ005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Car Customization","end_time_seconds":"1713942651"}}

View File

@@ -1,9 +1 @@
<<<<<<< HEAD
<<<<<<< HEAD
{"count":1,"self":159.4891264,"total":161.4726944,"children":{"InitializeActuators":{"count":3,"self":0.0017177,"total":0.0017177,"children":null},"InitializeSensors":{"count":3,"self":0.0035045999999999996,"total":0.0035045999999999996,"children":null},"AgentSendState":{"count":7823,"self":0.21347139999999998,"total":0.3103626,"children":{"CollectObservations":{"count":4695,"self":0.0624739,"total":0.0624739,"children":null},"WriteActionMask":{"count":4695,"self":0.0065712999999999995,"total":0.0065712999999999995,"children":null},"RequestDecision":{"count":4695,"self":0.027846,"total":0.027846,"children":null}}},"DecideAction":{"count":7823,"self":1.3662385,"total":1.3839671,"children":{"RayPerceptionSensor.Perceive":{"count":9390,"self":0.0177286,"total":0.0177286,"children":null}}},"AgentAct":{"count":7823,"self":0.28402109999999997,"total":0.28402109999999997,"children":null}},"gauges":{"BensonV6.1.CumulativeReward":{"count":14,"max":-0.163073957,"min":-0.244621739,"runningAverage":-0.203467548,"value":-0.166420355,"weightedAverage":-0.199763283}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713940415","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 985081e8-b814-4bc7-8736-608aea67ce7e -accessToken fMKSu_LeJtSMMwbIluJ0HvaiatLXHDxWic8X4MA6BEQ005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Racetrack mini","end_time_seconds":"1713940577"}}
=======
{"count":1,"self":13.0702272,"total":13.2399828,"children":{"InitializeActuators":{"count":2,"self":0.00099739999999999985,"total":0.00099739999999999985,"children":null},"InitializeSensors":{"count":2,"self":0.0015034,"total":0.0015034,"children":null},"AgentSendState":{"count":394,"self":0.0077031999999999995,"total":0.0247832,"children":{"CollectObservations":{"count":158,"self":0.004493,"total":0.004493,"children":null},"WriteActionMask":{"count":158,"self":0,"total":0,"children":null},"RequestDecision":{"count":158,"self":0.012587,"total":0.012587,"children":null}}},"DecideAction":{"count":394,"self":0.1281029,"total":0.1290791,"children":{"RayPerceptionSensor.Perceive":{"count":316,"self":0.0009762,"total":0.0009762,"children":null}}},"AgentAct":{"count":394,"self":0.0108823,"total":0.0108823,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713938654","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\Magnus\\Desktop\\UnityStuf\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-Magnus -hubSessionId 8870a2b5-eb85-482c-9f97-a69682ef9b2b -accessToken U1Q6bPAeMgVc12tgfRzGzGVn7bYVzdxATeIOIKVjt3o005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Racetrack mini","end_time_seconds":"1713938667"}}
>>>>>>> e5ca63e64be4e6649cff2239dddc8b93f8132a10
=======
{"count":1,"self":13.0702272,"total":13.2399828,"children":{"InitializeActuators":{"count":2,"self":0.00099739999999999985,"total":0.00099739999999999985,"children":null},"InitializeSensors":{"count":2,"self":0.0015034,"total":0.0015034,"children":null},"AgentSendState":{"count":394,"self":0.0077031999999999995,"total":0.0247832,"children":{"CollectObservations":{"count":158,"self":0.004493,"total":0.004493,"children":null},"WriteActionMask":{"count":158,"self":0,"total":0,"children":null},"RequestDecision":{"count":158,"self":0.012587,"total":0.012587,"children":null}}},"DecideAction":{"count":394,"self":0.1281029,"total":0.1290791,"children":{"RayPerceptionSensor.Perceive":{"count":316,"self":0.0009762,"total":0.0009762,"children":null}}},"AgentAct":{"count":394,"self":0.0108823,"total":0.0108823,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713938654","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\Magnus\\Desktop\\UnityStuf\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-Magnus -hubSessionId 8870a2b5-eb85-482c-9f97-a69682ef9b2b -accessToken U1Q6bPAeMgVc12tgfRzGzGVn7bYVzdxATeIOIKVjt3o005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Racetrack mini","end_time_seconds":"1713938667"}}
>>>>>>> 6da99da8c2f8207a43f20c59211df05003d51cb1
{"count":1,"self":260.8801792,"total":263.71180169999997,"children":{"InitializeActuators":{"count":2,"self":0.0012793,"total":0.0012793,"children":null},"InitializeSensors":{"count":2,"self":0.0020053,"total":0.0020053,"children":null},"AgentSendState":{"count":12917,"self":0.3768938,"total":0.4890713,"children":{"CollectObservations":{"count":5168,"self":0.058553799999999996,"total":0.058553799999999996,"children":null},"WriteActionMask":{"count":5168,"self":0.0059936999999999994,"total":0.0059936999999999994,"children":null},"RequestDecision":{"count":5168,"self":0.0429868,"total":0.04763,"children":{"RayPerceptionSensor.Perceive":{"count":5168,"self":0.0046432,"total":0.0046432,"children":null}}}}},"DecideAction":{"count":12917,"self":2.0233914,"total":2.0547198,"children":{"RayPerceptionSensor.Perceive":{"count":10336,"self":0.0313284,"total":0.0313284,"children":null}}},"AgentAct":{"count":12917,"self":0.2830542,"total":0.2830542,"children":null}},"gauges":{"BensonV7.CumulativeReward":{"count":1,"max":25.1733932,"min":25.1733932,"runningAverage":25.1733932,"value":25.1733932,"weightedAverage":25.1733932}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713945905","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 985081e8-b814-4bc7-8736-608aea67ce7e -accessToken fMKSu_LeJtSMMwbIluJ0HvaiatLXHDxWic8X4MA6BEQ005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Racetrack mini","end_time_seconds":"1713946168"}}

File diff suppressed because it is too large Load Diff

View File

@@ -33,6 +33,8 @@ public class AgentController: Agent
public int distanceBetweenCheckpoints = 5;
public bool ignoreMentalPain = true;
bool isEnabled = true;
public bool isPlaying = false;
[HideInInspector] public bool isFinished = false; // needed for gamemanager
protected override void OnDisable()
{
@@ -56,9 +58,13 @@ public class AgentController: Agent
return;
stepsSinceCheckpoint = 0;
checkpointsCollected = 0;
totalReward = 0;
totalMentalPain = 0;
checkpointsCollected = 0;
// don't reset car unless in training
if (isPlaying)
return;
// reset wheels
foreach (var wheel in wheels)
@@ -92,6 +98,12 @@ public class AgentController: Agent
public override void CollectObservations(VectorSensor sensor)
{
if (!isEnabled)
{
for (int i = 0; i < 6; i++)
sensor.AddObservation(0);
return;
}
Transform currentCheckpoint = checkpoints[checkpointsCollected].transform;
@@ -249,7 +261,16 @@ public class AgentController: Agent
if (checkpointsCollected == checkpoints.Count - 1)
{
AddReward(10f);
if (isPlaying)
{
isFinished = true;
}
EndEpisode();
}
checkpointsCollected += 1;
@@ -268,7 +289,34 @@ public class AgentController: Agent
if (stepsSinceCheckpoint >= maxStepsPerCheckpoint)
{
stepsSinceCheckpoint = 0;
EndEpisode();
if (isPlaying) // send back to previous checkpoint if stuck
{
if (checkpointsCollected == 0)
{
transform.position = startPosition;
transform.rotation = startRotation;
}
else
{
transform.position = new Vector3(
checkpoints[checkpointsCollected - 1].transform.position.x,
transform.position.y + 3,
checkpoints[checkpointsCollected - 1].transform.position.z
);
transform.eulerAngles = new Vector3(
transform.eulerAngles.x,
checkpoints[checkpointsCollected - 1].transform.eulerAngles.y,
transform.eulerAngles.z
);
}
rb.velocity = Vector3.zero;
}
else
EndEpisode();
}
// print(GetCumulativeReward());

View File

@@ -15,8 +15,17 @@ public class CarLoader : MonoBehaviour
public GameObject targetcar;
void Start()
{
carType = GameObject.Find("Car Data").GetComponent<CarData>().carType;
carColor = GameObject.Find("Car Data").GetComponent<CarData>().carColor;
try
{
carType = GameObject.Find("Car Data").GetComponent<CarData>().carType;
carColor = GameObject.Find("Car Data").GetComponent<CarData>().carColor;
}
catch (System.Exception)
{
carType = "Racecar";
carColor = "Default";
print("no loading");
}
foreach (GameObject car in Cars)
{

View File

@@ -24,16 +24,40 @@ public class GameManager : MonoBehaviour
// Update is called once per frame
void Update()
{
foreach (GameObject player in players)
for (int i = 0; i < players.Count(); i++)
{
try
GameObject player = players[i];
bool isAI = true;
if (player.GetComponent<PlayerController>().enabled)
isAI = false;
if (isAI)
{
bool isFinished = player.GetComponent<AgentController>().isFinished;
if (isFinished)
{
player.GetComponent<AgentController>().isFinished = false;
playerLaps[i] += 1;
}
}
else
{
int checkpointsCollected = player.GetComponent<PlayerController>().checkpointsCollected;
if (checkpointsCollected == checkpoints.Count())
{
player.GetComponent<PlayerController>().checkpointsCollected = 0;
playerLaps[i] += 1;
}
}
catch
if (playerLaps[i] > lapAmount)
{
int checkpointsCollected = player.GetComponent<AgentController>().checkpointsCollected;
player.GetComponent<Rigidbody>().isKinematic = true;
}
}
}
}