Traffic system

Hello everyone,

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?

Thank you in advance,

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.

Apologies for the rather dramatic example.

Thank you for your response.

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?

Below is the blueprint.

Uh mate, you haven’t plugged the forloop node to anything, it will always return only the first one.

When I plugin the forloop it does not even check the first node I do not know why!

Drag off the OutActors from the Get All Actors of Class and do a ForAllLoop.

Thank you Pinworm it worked :o