I created a rectangle shape with the gun and I decreased the bullet velocity to 0, so I can see where each bullet is spawned.
The top-center of the gun is the start position (and where each bullet must spawn) and the crossing of pink lines is the origin of the sprite.
Here my method where I’m trying to calculate:
public Vector2 getWeaponPosition()
{
float angle = weapon.getRotation()*MathUtils.PI/180; //To Radians
float ox = weapon.getX()+weapon.getWidth()/2; //Ori x
float oy = weapon.getY(); //Ori y
float px = weapon.getX()+weapon.getWidth()/2; //Start X
float py = weapon.getY()+weapon.getHeight(); //Start Y
Vector2 newPos = new Vector2();
newPos.x = MathUtils.cos(angle) * (px-ox) - MathUtils.sin(angle) * (py-oy) + ox;
newPos.y = MathUtils.sin(angle) * (px-ox) + MathUtils.cos(angle) * (py-oy) + oy;
return newPos;
}
http://s9.postimg.org/4xanky8jj/aaaa.png
The gun follows the mouse position perfectly.
**I’m using radians because MathUtils use radians.
Solved, found the solluiton on MrPork topic about direction.