Game manager WIP
This commit is contained in:
@@ -28,7 +28,7 @@ public class AgentControllerV7 : Agent
|
||||
float totalReward = 0;
|
||||
float totalMentalPain = 0;
|
||||
int stepsSinceCheckpoint = 0;
|
||||
int checkpointsReached = 0;
|
||||
[HideInInspector] public int checkpointsCollected = 0;
|
||||
public int maxStepsPerCheckpoint = 300;
|
||||
public int distanceBetweenCheckpoints = 5;
|
||||
public bool ignoreMentalPain = true;
|
||||
@@ -48,7 +48,7 @@ public class AgentControllerV7 : Agent
|
||||
public override void OnEpisodeBegin()
|
||||
{
|
||||
stepsSinceCheckpoint = 0;
|
||||
checkpointsReached = 0;
|
||||
checkpointsCollected = 0;
|
||||
totalReward = 0;
|
||||
totalMentalPain = 0;
|
||||
|
||||
@@ -84,7 +84,7 @@ public class AgentControllerV7 : Agent
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
{
|
||||
Transform currentCheckpoint = checkpoints[checkpointsReached].transform;
|
||||
Transform currentCheckpoint = checkpoints[checkpointsCollected].transform;
|
||||
|
||||
// distance to next checkpoint
|
||||
sensor.AddObservation(distanceToCheckpoint(currentCheckpoint));
|
||||
@@ -213,7 +213,7 @@ public class AgentControllerV7 : Agent
|
||||
}
|
||||
|
||||
// rewards
|
||||
Transform currentCheckpoint = checkpoints[checkpointsReached].transform;
|
||||
Transform currentCheckpoint = checkpoints[checkpointsCollected].transform;
|
||||
|
||||
float checkpintDistance = distanceToCheckpoint(currentCheckpoint);
|
||||
float reward = (1 - Mathf.InverseLerp(0, distanceBetweenCheckpoints, checkpintDistance)) / 500;
|
||||
@@ -235,13 +235,13 @@ public class AgentControllerV7 : Agent
|
||||
stepsSinceCheckpoint = 0;
|
||||
|
||||
// If last checkpoint
|
||||
if (checkpointsReached == checkpoints.Count - 1)
|
||||
if (checkpointsCollected == checkpoints.Count - 1)
|
||||
{
|
||||
AddReward(10f);
|
||||
EndEpisode();
|
||||
}
|
||||
|
||||
checkpointsReached += 1;
|
||||
checkpointsCollected += 1;
|
||||
|
||||
//TODO fix variable names
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ public class GameManager : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
foreach (GameObject player in players)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,12 @@ public class PlayerController : MonoBehaviour
|
||||
public float maxSpeed = 20;
|
||||
public float steeringRange = 30;
|
||||
public float steeringRangeAtMaxSpeed = 10;
|
||||
|
||||
public float autoBrake;
|
||||
|
||||
//public GameObject lookat;
|
||||
public AudioSource audio;
|
||||
|
||||
WheelControl[] wheels;
|
||||
public Rigidbody rigidBody;
|
||||
[HideInInspector] public int checkpointsCollected = 0;
|
||||
public GameObject[] checkpoints;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -123,7 +121,6 @@ public class PlayerController : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnCollisionEnter(Collision other) {
|
||||
|
||||
if (other.gameObject.tag == "Wall")
|
||||
@@ -131,4 +128,14 @@ public class PlayerController : MonoBehaviour
|
||||
// audio.Play();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other) {
|
||||
print(checkpointsCollected);
|
||||
Transform currentCheckpoint = checkpoints[checkpointsCollected].transform;
|
||||
if (other.gameObject == currentCheckpoint)
|
||||
{
|
||||
checkpointsCollected += 1;
|
||||
print(checkpointsCollected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user