Let's assume you have a turret that faces the right when the rotation property is 0. It has 2 barrels that reach out 10 pixels to the right of the origin of the turret, and one barrel is 5 pixels above the origin and the other is 5 pixels below. You want both bullets to appear on the ends of both barrels.
PHP Code:
var turretRotationInRadians:Number = turret.rotation * Math.PI / 180;
bulletLeft.x = Math.cos (turretRotationInRadians) * 10 + Math.sin (turretRotationInRadians) * -5;
bulletLeft.y = Math.cos (turretRotationInRadians) * -5 + Math.sin (turretRotationInRadians) * 10;
bulletRight.x = Math.cos (turretRotationInRadians) * 10 + Math.sin (turretRotationInRadians) * 5;
bulletRight.y = Math.cos (turretRotationInRadians) * 5 + Math.sin (turretRotationInRadians) * 10;
//Left is the barrel on the left when the turret is facing north
I think that's as complex as it gets. Though it might not be right cause I might have mixed up the positive and negative signs. The last time I used trigonometry was before summer started so..
For problems like this I tackle them by thinking what formula will get the bullets to appear at the point I want them to (although this sounds like a bad approach to any problem). I'll only explain the x position of the left bullet. When the turret faces east (0 rotation) the bullet's must be +10. Facing south (90 rotation) it must be +5. West is -10. North is -5. So what gives me +10 at 0 rotation and -10 and 180 rotation? That would be
PHP Code:
Math.cos (rotation * Math.PI / 180) * 10;
Then what gives me +5 at 90 rotation and -5 at 270 rotation?
PHP Code:
Math.sin (rotation * Math.PI / 180) * 5;
Put it all together and you get
PHP Code:
x = Math.cos (......) * 10 + Math.sin (......) * 5;
This is how I solved this exact same issue when I came across it.