mEgre
This commit is contained in:
@@ -266,7 +266,6 @@ public class AgentControllerV6 : Agent
|
||||
|
||||
totalReward = 0;
|
||||
|
||||
print("checkpoint");
|
||||
}
|
||||
|
||||
currentStep += 1;
|
||||
|
||||
@@ -20,8 +20,8 @@ public class AgentControllerV7 : Agent
|
||||
public float steeringRangeAtMaxSpeed = 7;
|
||||
public float autoBrake = 100;
|
||||
WheelControl[] wheels;
|
||||
Rigidbody rigidBody;
|
||||
public List<GameObject> checkpoints;
|
||||
Rigidbody rb;
|
||||
Vector3 startPosition;
|
||||
Quaternion startRotation;
|
||||
int currentStep = 0;
|
||||
@@ -36,10 +36,10 @@ public class AgentControllerV7 : Agent
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rigidBody = GetComponent<Rigidbody>();
|
||||
rb = GetComponent<Rigidbody>();
|
||||
// Find all child GameObjects that have the WheelControl script attached
|
||||
wheels = GetComponentsInChildren<WheelControl>();
|
||||
|
||||
|
||||
startPosition = transform.localPosition;
|
||||
startRotation = transform.localRotation;
|
||||
|
||||
@@ -64,8 +64,8 @@ public class AgentControllerV7 : Agent
|
||||
// reset car
|
||||
transform.localPosition = startPosition;
|
||||
transform.localRotation = startRotation;
|
||||
rigidBody.velocity = Vector3.zero;
|
||||
rigidBody.angularVelocity = Vector3.zero;
|
||||
rb.velocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
@@ -98,9 +98,9 @@ public class AgentControllerV7 : Agent
|
||||
|
||||
// relative Velocity
|
||||
Vector3 velocity = new Vector3(
|
||||
rigidBody.velocity.x,
|
||||
rb.velocity.x,
|
||||
0,
|
||||
rigidBody.velocity.z
|
||||
rb.velocity.z
|
||||
);
|
||||
|
||||
Vector3 relativeVelocity = Quaternion.Euler(0, -carAngle, 0) * velocity;
|
||||
@@ -133,7 +133,7 @@ public class AgentControllerV7 : Agent
|
||||
if (ignoreMentalPain)
|
||||
totalReward -= 0.0018f;
|
||||
|
||||
float forwardSpeed = Vector3.Dot(transform.forward, rigidBody.velocity);
|
||||
float forwardSpeed = Vector3.Dot(transform.forward, rb.velocity);
|
||||
// Calculate how close the car is to top speed
|
||||
// as a number from zero to one
|
||||
float speedFactor = Mathf.InverseLerp(0, maxSpeed / 4, forwardSpeed);
|
||||
@@ -218,12 +218,11 @@ public class AgentControllerV7 : Agent
|
||||
|
||||
if (checkpintDistance < 0.1f)
|
||||
{
|
||||
currentCheckpoint.GetComponent<Checkpoint>().isCollected = true;
|
||||
stepsSinceCheckpoint = 0;
|
||||
checkpointsReached += 1;
|
||||
|
||||
// If last checkpoint
|
||||
if (currentCheckpoint == checkpoints[checkpoints.Count - 1].transform)
|
||||
if (checkpointsReached == checkpoints.Count - 1)
|
||||
{
|
||||
AddReward(10f);
|
||||
EndEpisode();
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Garage : MonoBehaviour
|
||||
@@ -13,6 +14,7 @@ public class Garage : MonoBehaviour
|
||||
public Button[] ColorButtons;
|
||||
public Material[] Colors;
|
||||
quaternion currentRotation;
|
||||
public Button startButton;
|
||||
void Start()
|
||||
{
|
||||
CarButtons[0].onClick.AddListener(SelectHotrod);
|
||||
@@ -37,6 +39,8 @@ public class Garage : MonoBehaviour
|
||||
ColorButtons[10].onClick.AddListener(SelectWhite);
|
||||
ColorButtons[11].onClick.AddListener(SelectYellow);
|
||||
|
||||
startButton.onClick.AddListener(startGame);
|
||||
|
||||
disable();
|
||||
SelectHotrod();
|
||||
}
|
||||
@@ -62,6 +66,11 @@ public class Garage : MonoBehaviour
|
||||
CurrentCar.transform.rotation = currentRotation;
|
||||
}
|
||||
|
||||
void startGame()
|
||||
{
|
||||
SceneManager.LoadScene("Racetrack mini");
|
||||
}
|
||||
|
||||
void SelectHotrod()
|
||||
{
|
||||
SelectCar(0);
|
||||
|
||||
25
Assets/Scripts/Car Loader.cs
Normal file
25
Assets/Scripts/Car Loader.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CarLoader : MonoBehaviour
|
||||
{
|
||||
public GameObject Hotrod;
|
||||
GameObject playerCar;
|
||||
void Start()
|
||||
{
|
||||
playerCar = GameObject.Find("Car Data").GetComponent<CarData>().playerCar;
|
||||
|
||||
replaceCar(Hotrod);
|
||||
|
||||
}
|
||||
|
||||
void replaceCar(GameObject car)
|
||||
{
|
||||
Transform carTransform = car.transform;
|
||||
|
||||
playerCar.transform.position = carTransform.position;
|
||||
playerCar.transform.rotation = carTransform.rotation;
|
||||
playerCar.transform.localScale = carTransform.localScale;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Car Loader.cs.meta
Normal file
11
Assets/Scripts/Car Loader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7750762847caa7b4bbc035455344adf9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Scripts/Game Manager.cs
Normal file
11
Assets/Scripts/Game Manager.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CarData : MonoBehaviour
|
||||
{
|
||||
public GameObject playerCar;
|
||||
private void Awake() {
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Game Manager.cs.meta
Normal file
11
Assets/Scripts/Game Manager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb30df1407c4e1348a03c058cb70c8ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user