//Let's pretend this is as a triangle i_ //imaginary |.\_ p\..\_ //player ...\__.......m //mouse Here is my attempt to implement the algorithm : a=1; //a is the side that goes from player crds to imaginary point b=sqrt((mouse_x-xplayer)*(mouse_x-xplayer)+(mouse_y-yplayer)*(mouse_y-yplayer)); //b is the other side of the triangle, it goes from player crds to mouse crds c=sqrt((mouse_x-xplayer)*(mouse_x-xplayer)+(mouse_y-(yplayer-1))*(mouse_y-(player-1))); //c is the side opposite to the angle, it goes from i to m angle=acos((c*c)/(2.0*a*a*b*b)); if(mouse_x<xplayer) angle+=pii; |