Car Ahead other

Hi all,
i have a problem and i can’t solve so i m posting here a question ,
i have two vehicles , i know position and velocity vector, so how to know if a vehicle is front of other.

(carBPosition - carAPosition).DotProduct(carADirection) should get you the distance car B is ahead of car A. This is called scalar projection.
Note that this is relative to car A, and dependent of that car’s rotation. I have no experience creating racing games, but you may want to combine this with checkpoints to cut up the track into smaller pieces that are aware of their general direction… this way, overtaking a car is like passing a moving checkpoint in between two stationary ones.


Welcome back CarloMaker. Have you lost access to your original or transferred account?

Maybe one of the mods here can help…

@Modanung Many thanks !
@rasteron hi, thanks, i just recover my profile!

Urho3D also has the Vector3::ProjectOntoAxis function. This normalizes the axis parameter and then does a DotProduct.

Any examples of usage?