title: My bullet class is shooting in the wrong direction. what am I doing wrong?
body: <p>This is my bullet class. I have been trying to make my bullet go in a direction I get from the mouse. </p>
  
  <p>But the problem is when I shoot a bullet it is not going in the direction I want. Sometimes it is right but mostly it is off by around 20 pixels. </p>
  
  <pre><code>public class Bullet extends Entity {
  
      public Bullet(int x, int y, int width, int height, boolean solid, Id id,
          GameHandler handler,int targetPosX, int targetPosY, int speed) {
          super(x, y, width, height, solid, id, handler);
  
          this.setTargetPosX(targetPosX);
          this.setTargetPosY(targetPosY);
          this.speed = speed;
  
          angle = Math.toDegrees(Math.atan2(targetPosY-y, targetPosX-x));     
      }
  
      @Override
      public void render(Graphics g) {
          g.setColor(Color.BLACK);
          g.fillOval(x-(width/2), y-(height/2), width, height);
      }
  
      @Override
      public void update() {
          x += (float)(Math.cos(Math.toRadians(angle)))*speed;
          y += (float)(Math.sin(Math.toRadians(angle)))*speed;
      }
  
      public void moveToTarget(){
      }
  
      public int getTargetPosX() {
          return targetPosX;
      }
  
      private void setTargetPosX(int targetPosX) {
          this.targetPosX = targetPosX;
      }
  
      public int getTargetPosY() {
          return targetPosY;
      }
  
      private void setTargetPosY(int targetPosY) {
          this.targetPosY = targetPosY;
      }
  
      public int getSpeed() {
          return speed;
      }
  }
  </code></pre>
  
  <p>This is my Cursor class:</p>
  
  <pre><code>public class GameCursor extends Entity {
  
      private LinkedList&lt;Bullet&gt; bulletList = new LinkedList&lt;Bullet&gt;();
  
  private enum State{
      AIM,
      DEFULT,
      RELODING;   
  }
  
  
  
  public GameCursor(Entity en,GameHandler handler) {
  
      super(MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y, 0, 0, false, Id.cursor , handler);
  
      this.state = State.AIM;
              this.en = en;
  
  }
  
  @Override
  public synchronized void  render(Graphics g) {
      switch(this.state){
          case AIM:             
              g.setColor(Color.red);
              g.drawOval(x-15, y-15, 30, 30);
              g.fillRect(x, y, 1, 1);             
              break;
      }
  
      for(Bullet b: getBulletList()){
          b.render(g);
      }
  }
  
  @Override
  public synchronized void update() { 
  
  
          x = MouseInput.getMousePosX()-(-en.getX() + Frame.WIDTH/2);
          y = MouseInput.getMousePosY()-(-en.getY() + Frame.HEIGHT/2 + 100);
  
  
                      for(Bullet b: getBulletList()){
                          b.update();
  
                      }
  
  
  
  }
  
      public void shoot(){
          Bullet b = new Bullet(en.getX() + (en.width/2) ,en.getY()+ (en.height/2),10,10,true, Id.bullet, handler, getX(), getY(), 12);
          addBullet(b);
  
  
      }
  }
  </code></pre>