The online racing simulator
InSim Direction help.
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))

#2 - kdo
Set
if ((LowestDistance < 250)

to
if ((LowestDistance < 100)

250= 250 metter around the car, so put 100 should be better
Quote from jobans :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))


This is not a particularly easy job. You'd have to use a bit of vector maths to reliably determine what's in front of the car and how far it is...
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.
I dont think it will be good idea with nodes. Anyone have more ideas?
Nodes are meant for EXACTLY this case. (Amongst other things.)
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...
How? Can you please give me some code exaple?
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

posVectX = chasedCar.X - copCar.X
posVectY = chasedCar.Y - copCar.Y

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)
Attached files
Vector_angles.pdf - 29.1 KB - 390 views

FGED GREDG RDFGDR GSFDG