PDA

View Full Version : InSim Direction help.


jobans
31st December 2011, 08:31
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))

kdo
31st December 2011, 10:11
Set
if ((LowestDistance < 250)to
if ((LowestDistance < 100)

250= 250 metter around the car, so put 100 should be better

MadCatX
31st December 2011, 12:57
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...

DarkTimes
31st December 2011, 22:21
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.

jobans
1st January 2012, 09:00
I dont think it will be good idea with nodes. Anyone have more ideas? :)

Dygear
1st January 2012, 18:19
Nodes are meant for EXACTLY this case. (Amongst other things.)

MadCatX
1st January 2012, 18:49
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...

jobans
1st January 2012, 19:16
How? :D Can you please give me some code exaple?

MadCatX
2nd January 2012, 00:44
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)