First off I'm new here so I'd like to say nice to meet you all . Now down to business, I'm working on a (2d, birds i view) game but I'm having trouble with interacting with the avatar. I would like to make it so the avatar faces the mouse cursor (so it rotates so the front always is facing the mouse). This is what I have but the code just has the avatar spinning constantly. (Note: I changed some variable names and some of the syntax to make it easier to understand my code without knowledge of the game engine I'm using so any var names or brackets/parenthesis problems aren't an issue.) Thanks in advance for the any help!
if (mousesX >= avatarsX) { if(mousesY >= avatarsY) angle = (int)(Math.atan((mousesY - avatarsY) / (mousesX -avatarsX))); else angle = (int)(Math.atan((avatarsY - mousesY) / (mousesX - avatarsX))); } else { if(mousesY >= avatarsY) angle = (int)(Math.atan(mousesY -avatarsY)/(avatarsX - mousesX)); else angle = (int)(Math.atan((avatarsY - mousesY) / (avatarsX - mousesX)); } if(angle != oldAngle) {( setImage(rotate(getImage() , angle + oldAngle + (180 - (angle + oldAngle)))); //rotate(image, int) rotates image (in this case the avitar) by int degrees clockwise. setImage(image) displays image (the avatar) and getImage() returns the avatars image oldAngle += angle; } if (oldAngle == 360) oldAngle -= 360;