This question already has an answer here:

I am making an creature simulator where the creatures have a neural net for a brain.

One of the inputs to the net is the angle it has to travel to go to be facing the nearest piece of food. I can get the nearest piece of food, but I need a way of getting the angle it needs to travel to be facing the piece of food.

For example, if it was facing the food, it would be zero, and if it was facing away it would be 180. I got the creatures angle, if it is facing up it would be 0 degrees, and if its facing right its 90 degrees.


marked as duplicate by Seth Battin, Nathan Reed, bummzack, MichaelHouse Aug 4 '13 at 23:57

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.


look up dot product on wikipedia. You need to calculate the dot product of the normalized direction vector you are facing and the normal vector of the surface. something like x1*x2+y1*y2. To get the angle between the two vectors you have to use the acos function.


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