Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question is an exact duplicate of:

I am building a car racing game using the coordinate system in which I have enemies's cars and the player cars. I want to ask that what is the best way to find the the direction of enemies's cars so that they would facing the player's car and move towards the player's car.

share|improve this question

marked as duplicate by Anko, msell, Josh Petrie, Byte56, Sean Middleditch May 30 '13 at 0:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Isn't this the same as your other question?… – Tetrad May 24 '13 at 14:33

If you mean that you want the direction for the enemies to face so that they're looking at the player's car, it's literally just maths. You need to calculate the vector between the enemy and the player, and then normalise it so it's a direction. Code example:

Vector3 direction = Vector3.Normalise(player.position - enemy.position);
share|improve this answer
You should also note that (player.Position - enemy.Position) would also provide you with the distance between the two, prior to Normalizing. – Jon May 24 '13 at 10:01
@Jon Fair enough, although I don't know how useful that would be to the OP – Polar May 24 '13 at 10:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.