I am trying to build a traffic system to my city, but I have a problem in measuring the distance between two cars, e.g, I want to calculate the distance between me and a car which is in front of me (not behind). Is there a way to calculate the distance between certain object and other objects which are only in front of that certain object?
Try PositionA - PositionB → vector length. That ought to do it. Not sure what you mean by ‘in front of you’ - only when the camera is facing the object or they’re in a cone of view? Perhaps it’s as simple as checking whether X/Y position of the target object is larger/smaller than the player’s position.
Imagine you’re driving a car forward but peek through the left window with the Uzi in your hand - is ‘in front of me’ on the road, ahead of the car or on the sidewalk, where I’m looking.
I was able to make the car stop by adding a collision box in front of the car and when it collide with specific class of cars it stops. The the problem is it only check the first index of the class. E.g, the car stops only once it faces the car of the Sedan class which has the index 0, but when it faces another car (which has index 1 or 2) from the same class “Sedan” it does not stop.
Is there a way to detect all the actors of certain class?