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.