How to make that Cruise InSim police system catch only car what is in front. Now I have this code but it would be more realistic that it recognise only cars what is in front not all around in some distance.
if ((LowestDistance < 250) && (LowestDistance > 0))
You could try using track nodes to figure it out. You could keep track of whether the player is going up through the nodes or down, to track what direction they are going. Then to get the car in front you can just find the car that is on the next closest node in the direction they are travelling. This wouldn't work for open-configs, and probably wouldn't be perfect, but it might just work dammit.
If he wants to use it with open config, I suppose it won't work, right?
@jobans: Are you able to implement a not-so-complicated algorithm that would determine which cars are in front of a cop car based on its motion vector? It really sounds more terrifying that it is, but some 2nd year high school math is involved...
It's kinda hard to give code examples for someone else's program, but I can show you how to calculate an angle between two objects using vectors (see the attached PDF).
Knowing this, you can obtain motion vector of a cop car (the direction the car is moving expressed in X, Y "coordinates"). Then you can get a position vector of a chased car relative to the cop car like
Then you simply calculate the angle between cop car's motion vector and chased car's position vector and if this angle is less than say 30°, you allow for the chased car to be caught.
All data you need for this should be in the MCI packet.
(You can visualize the math described in the PDF by drawing the vectors on a squared paper. I'm running a slight fever here and it's almost 3 AM, so I don't really guarantee that it will work in all cases - feel free to correct me or suggest a better approach; an atan2 function in some math libraries might be useful here)