Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
    
Isn't this the same as your other question? gamedev.stackexchange.com/questions/56088/… –  Tetrad May 24 '13 at 14:33
add comment

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.

1 Answer

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
add comment

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