private void UpdateGoal() { foreach (KeyValuePair <GameObject, int> entry in companionCars) { GameObject car = entry.Key; int lane = entry.Value; DrivingMode drivingMode = companionCarModes[car.name]; // Select lane and longitudinal goal int maxLaneChange = 1; float maxZ = trackLength / 2; float goalZ; int newLane; switch (drivingMode) { default: { goalZ = Mathf.Clamp(Random.Range(car.transform.position.z - maxZ, car.transform.position.z + maxZ), trackLength * 0.1f, trackLength * 0.9f); newLane = Mathf.Clamp(Random.Range(lane - maxLaneChange, lane + maxLaneChange), 0, numLanes); break; } case DrivingMode.PURSUIT: { goalZ = egoCar.transform.position.z; newLane = Mathf.Clamp(NearestLane(egoCar.transform.position.x), lane - maxLaneChange, lane + maxLaneChange); break; } } // Only change lanes if not moving backwards if (goalZ < car.transform.position.z) { newLane = lane; } Vector3 goalPos = new Vector3(laneLines[newLane] - laneMidPointOffset, 0, goalZ); if (!PathOccupied(car, goalPos)) { Debug.Log(string.Format("{0} goal: {1}", car.name, goalPos)); car.gameObject.GetComponent <CompanionCarInterface>().SetTargetPosition(goalPos); } } }
public override int GetHashCode() { int hash = 1; if (header_ != null) { hash ^= Header.GetHashCode(); } if (DrivingMode != 0) { hash ^= DrivingMode.GetHashCode(); } if (Action != 0) { hash ^= Action.GetHashCode(); } return(hash); }
public Car(CarType type, double initialVelocity, DrivingMode drivingMode) { Type = type; Velocity = initialVelocity; DrivingMode = drivingMode; }
public void SetDrivingMode(string carName, DrivingMode mode) { companionCarModes[carName] = mode; }
public override int GetHashCode() { int hash = 1; if (X != 0D) { hash ^= X.GetHashCode(); } if (Y != 0D) { hash ^= Y.GetHashCode(); } if (Z != 0D) { hash ^= Z.GetHashCode(); } if (Timestamp != 0D) { hash ^= Timestamp.GetHashCode(); } if (Roll != 0D) { hash ^= Roll.GetHashCode(); } if (Pitch != 0D) { hash ^= Pitch.GetHashCode(); } if (Yaw != 0D) { hash ^= Yaw.GetHashCode(); } if (Heading != 0D) { hash ^= Heading.GetHashCode(); } if (Kappa != 0D) { hash ^= Kappa.GetHashCode(); } if (LinearVelocity != 0D) { hash ^= LinearVelocity.GetHashCode(); } if (AngularVelocity != 0D) { hash ^= AngularVelocity.GetHashCode(); } if (LinearAcceleration != 0D) { hash ^= LinearAcceleration.GetHashCode(); } if (Gear != 0) { hash ^= Gear.GetHashCode(); } if (DrivingMode != 0) { hash ^= DrivingMode.GetHashCode(); } if (pose_ != null) { hash ^= Pose.GetHashCode(); } return(hash); }