|
@@ -65,15 +65,19 @@ namespace TrafficSimulation {
|
|
|
|
|
|
void Start()
|
|
|
{
|
|
|
- wheelDrive = this.GetComponent<WheelDrive>();
|
|
|
+ this.wheelDrive = this.GetComponent<WheelDrive>();
|
|
|
|
|
|
if(trafficSystem == null)
|
|
|
return;
|
|
|
|
|
|
- initMaxSpeed = wheelDrive.maxSpeed;
|
|
|
+ this.initMaxSpeed = wheelDrive.maxSpeed;
|
|
|
SetWaypointVehicleIsOn();
|
|
|
}
|
|
|
|
|
|
+ private void OnEnable()
|
|
|
+ {
|
|
|
+ SetWaypointVehicleIsOn();
|
|
|
+ }
|
|
|
private void FixedUpdate()
|
|
|
{
|
|
|
if (trafficSystem == null)
|
|
@@ -173,12 +177,12 @@ namespace TrafficSimulation {
|
|
|
if (otherVehicle.maxSpeed < wheelDrive.maxSpeed && otherVehicle.maxSpeed > 0 && dotFront > .8f)
|
|
|
{
|
|
|
float ms = Mathf.Max(wheelDrive.GetSpeedMS(otherVehicle.maxSpeed) - .5f, .1f);
|
|
|
- //Debug.Log(obstacle.name + " slower. lower speed of " +gameObject.name + " to " + wheelDrive.GetSpeedUnit(ms) + "!");
|
|
|
+ Debug.Log(obstacle.name + " slower. lower speed of " +gameObject.name + " to " + wheelDrive.GetSpeedUnit(ms) + "!");
|
|
|
wheelDrive.maxSpeed = wheelDrive.GetSpeedUnit(ms);
|
|
|
}
|
|
|
else if(otherVehicle.maxSpeed == 0f)
|
|
|
{
|
|
|
- //Debug.Log(gameObject.name + ": Stopping because of " + obstacle.name +"!");
|
|
|
+ Debug.Log(gameObject.name + ": Stopping because of " + obstacle.name +"!");
|
|
|
acc = 0;
|
|
|
brake = 1;
|
|
|
wheelDrive.maxSpeed = 0f;
|
|
@@ -188,7 +192,7 @@ namespace TrafficSimulation {
|
|
|
//If the two vehicles are too close, and facing the same direction, brake the ego vehicle
|
|
|
if(hitDist < emergencyBrakeThresh && dotFront > .8f)
|
|
|
{
|
|
|
- //Debug.Log(gameObject.name + "Two close, same direction. Breaking");
|
|
|
+ Debug.Log(gameObject.name + "Two close, same direction. Breaking");
|
|
|
acc = 0;
|
|
|
brake = 1;
|
|
|
wheelDrive.maxSpeed = Mathf.Max(wheelDrive.maxSpeed / 2f, wheelDrive.minSpeed);
|
|
@@ -273,13 +277,13 @@ namespace TrafficSimulation {
|
|
|
for(float a=-initRay; a<=initRay; a+=raySpacing)
|
|
|
{
|
|
|
CastRay(raycastAnchor.transform.position, a, this.transform.forward, raycastLength, out detectedObstacle, out hitDist);
|
|
|
-
|
|
|
if(detectedObstacle == null){
|
|
|
continue;
|
|
|
- }
|
|
|
+ }
|
|
|
float dist = Vector3.Distance(this.transform.position, detectedObstacle.transform.position);
|
|
|
if(dist < minDist)
|
|
|
{
|
|
|
+ Debug.Log("Detected Object: " + detectedObstacle.name);
|
|
|
minDist = dist;
|
|
|
break;
|
|
|
}
|
|
@@ -327,6 +331,12 @@ namespace TrafficSimulation {
|
|
|
|
|
|
void SetWaypointVehicleIsOn()
|
|
|
{
|
|
|
+ if(trafficSystem.segments == null || trafficSystem.segments.Count == 0)
|
|
|
+ {
|
|
|
+ Debug.Log("Segments are null or count is 0");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
//Find current target
|
|
|
foreach(Segment segment in trafficSystem.segments)
|
|
|
{
|