Hi, i am currentlly trying to make 2d shooter and im having problem with rotating player to face the mouse. Here is my code:I pasted all of it, all variables are after the public class thing and the code to rotate is after tile map drawing loop in paint method. sorry for so much code im just starting to learn java so i dont know how to shorten it.import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.MouseInfo; import java.awt.Point; import java.awt.PointerInfo; import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JPanel; public class game extends JPanel implements Runnable, KeyListener, MouseMotionListener,MouseListener { private int posX, posY; private Thread thread; public int cx; public int cy; Char p =new Char(); public int x; public int y; public int wx; public int wy; BufferedImage grass, map; public BufferedImage tree; public BufferedImage player; public int L; public int U; public int in; public int CameraX; public int CameraY; int R = 64; int D = 64; int centerX = 800 / 2; int centerY = 800 / 2; float xDistance = cx - centerX; float yDistance = cy - centerY; double angle = Math.toDegrees(Math.atan2(yDistance, xDistance)); public void load(){ BufferedImage walkable = null; try { grass = ImageIO.read(new File("grass.png")); tree = ImageIO.read(new File("tree.png")); player = ImageIO.read(new File("player.png")); } catch(IOException e) { System.out.println("failed"); } } public game() { load(); addKeyListener(this); addMouseListener(this); addMouseMotionListener(this); requestFocusInWindow(); this.setFocusable(true); } public void addNotify(){ super.addNotify(); thread = new Thread(this); thread.start(); } public void paint(Graphics g){ super.paint(g); map m = new map(); Graphics2D g2 = (Graphics2D)g; Graphics2D world = (Graphics2D)g; //Graphics2D ob = (Graphics2D)g; world.drawImage(map, wx,wy, this); // DRAW HERO for (int y =0 ; y <= 19; y++){ for (int x = 0; x <= 19; x++){ int L = (x*64)+CameraX; int U = (y*64)+CameraY; int R = 64; int D = 64; /// g2d.rotate(Math.toRadians(-90)); if (m.map[y][x] == 0){ //g2d.setColor(Color.green); world.drawImage(grass,L,U,R,D,this); // g2d.setColor(Color.gray); // g2d.fillRect(L+64, U, 8, 64); } if (m.map[y][x] == 2){ world.setColor(Color.green); world.drawImage(grass,L,U,R,D,this); world.setColor(Color.green); world.drawImage(tree,L,U,R,D,this); } } ///g2d1.rotate(10); } /// g2d.drawLine(100, 100, 50, 50); AffineTransform trans = new AffineTransform(); AffineTransform identity = new AffineTransform(); trans.setTransform(identity); //trans.rotate(Math.toRadians(angle) ); trans.setToRotation(Math.toRadians(angle)); g2.translate(centerX, centerY); g2.drawImage(player, trans,this); g2.setColor(Color.black); g2.drawString("x = " + cx + " , y = " + cy, centerX-700, centerY-700); Toolkit.getDefaultToolkit().sync(); g.dispose(); } public void run() { while(true){ repaint(); } } @Override public void keyTyped(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { map m = new map(); int keyCode = e.getKeyCode(); switch( keyCode ) { case KeyEvent.VK_W: CameraY+=1; break; case KeyEvent.VK_D: CameraX-=1; break; case KeyEvent.VK_A: CameraX+=1; break; case KeyEvent.VK_S: CameraY-=1; break; } } @Override public void keyReleased(KeyEvent ke) { } public void mouseClicked(MouseEvent e) { // Point mc = new Point(cx=e.getX(), cy=e.getY()); } public void mousePressed(MouseEvent e) { // Point mc = new Point(cx=e.getX(), cy=e.getY()); } public void mouseReleased(MouseEvent me) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } public void mouseEntered(MouseEvent e) { // cy=e.getX(); // cy=e.getY(); } public void mouseMoved(MouseEvent e){ Point mc = new Point(cx=e.getX(), cy=e.getY()); } public void mouseExited(MouseEvent me) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseDragged(MouseEvent me) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }