[Solved] Can't get Bullets to Fire from Tip of Spaceship

Topics: User Forum
Jul 30, 2012 at 11:46 PM
Edited Jul 30, 2012 at 11:47 PM

Could someone please help for the life of me, I can't get my bullet sprites to fire from the tip of my spacecraft. I've got the bullets firing from center of spaceship, but I can't figure out how to make it instead fire from the tip of the spacecraft.

I have checked my collision filtering so Bullets and SpaceCraft are not colliding.

Code for my Create Bullet: The commented line of code should have placed the bullet launch at top center of my space craft...

Please advise.

bullets = new SpriteBullet(bulletTexture, BodyType.Dynamic, world, ObjectType.BULLET, this.screenSize);
//bullets.Body.Position = player.Body.Position + ConvertUnits.ToSimUnits(new Vector2(player.Texture.Width, player.Texture.Height / 2f));
bullets.Body.Position = player.Body.WorldCenter;
bullets.Body.Rotation = player.Body.Rotation;

Inside my Bullet class, this is the code for bullet's Update:

this.Body.ApplyLinearImpulse(this.Direction * (speedMove * (float)gameTime.ElapsedGameTime.TotalSeconds));
Jul 31, 2012 at 4:58 AM
Edited Jul 31, 2012 at 4:59 AM

Figured it out.

bullets = new SpriteBullet(bulletTexture, BodyType.Dynamic, world, ObjectType.BULLET, this.screenSize);
bullets.Body.Rotation = player.Body.Rotation;
bullets.Body.Position = player.Body.Position + ConvertUnits.ToSimUnits(new Vector2((float)Math.Cos(player.Body.Rotation) * player.Texture.Width, (float)Math.Sin(player.Body.Rotation) * player.Texture.Height/2f));