Hello,

I've always been afraid to work with everything that has with circles to do when programming and now I'm here! I've tried to spawn 2 bullets from a ship who can rotate 360 degrees. When the ships rotation is equal to 0 it works as it should but as soon as I rotate the ship things get ugly.

1. The ships rotation

My ship is rotating (looking towards) the direction you pull a joystick (this works perfectly)

theta = Math.atan2( shootingPad.getKnobX() - shootingPad.getWidth() / 2, shootingPad.getKnobY() - shootingPad.getHeight() / 2); theta += Math.PI; angle = (float) Math.toDegrees(theta); rotation = -angle;

The ship points towards the direction it should.

2. Spawning the bullet (let's try one of the bullets)

When I pull the joystick I also want the bullets to spawn with a small delay between each shot. The method to shoot looks like this:

private void shoot(){ double angle = rotation; float x2 = x; float y2 = y; gunRightTipX = getCenterX() - 36; gunRightTipY = getCenterY() - 48; float bulletX = x2 + (gunRightTipX * (float)Math.toRadians(Math.cos(angle)) - gunRightTipY * (float)Math.toRadians(Math.sin(angle))); float bulletY = y2 + (gunRightTipX * (float)Math.toRadians(Math.sin(angle)) + gunRightTipY * (float)Math.toRadians(Math.cos(angle))); Bullet b = new Bullet(new TextureRegion(Assets.bullet), bulletX, bulletY, (float)angle, 5f); bulletList.add(b); }

Where gunRightTipX and gunRightTipY is the end of the barrell where the shot is supposed to spawn.

This works fine when the rotation equals 0. But when I rotate the ship it seems that the spawn position's always the same or atleast very close to it. It doesn't follow the barrell point of the rotated ship..

3. The Bullet class

The bullets then travel in the direction they should (the direction the ship is facing)

(Render method for the class "Bullet")

public void render(SpriteBatch batch, float delta) { super.render(batch, delta); x += (float)(speed * Math.cos(Math.toRadians(angle - 90))) * delta * Assets.FPS; y += (float)(speed * Math.sin(Math.toRadians(angle - 90))) * delta * Assets.FPS; batch.draw(texture, x, y, texture.getRegionWidth() / 2, texture.getRegionHeight() / 2, texture.getRegionWidth(), texture.getRegionHeight(), 1, 1, (float)rotation); }

I really need help with this...

Thanks in advance!

**Edited by JohnnyBlomgren, 10 October 2013 - 04:21 AM.**