Bullets Shoot Crooked in Space Invaders Game

fatsomania36

  • Posts: 15
As some of you may be aware, I am making a space invaders game. At the moment, everything is working except one thing. The ship the player controls shoots its bullets out the left side and then straight. Sometimes it shoots them normally, just from the middle, but most of the time they come out the left side. This is not a problem I originally had when I created the game, but it is now. Does anyone know what is causing this?



Here are my blocks for firing the bullet:



I'm wondering if there's a conflict with the "Last created actor" because the enemy ships are firing as well.

JeffreyDriver

  • *
  • Posts: 2243
Looks like the bullets are being created at X0 Y0 of the ship. Change in to Y-Centre and that should fix it. If it's still not quite right, play with Y-Centre +/- small figures until it looks right.

Also, switching your collision shapes to sensors is worth doing.

fatsomania36

  • Posts: 15
OK, thanks. Changing it to a sensor fixed the problem, except now the bullets appear in front of the ship instead of behind, and I did change it to "at back".

JeffreyDriver

  • *
  • Posts: 2243
I think that front and back refer to layers. Under ACTORS > DRAW, there's blocks to position actors WITHIN the layers.

fatsomania36

  • Posts: 15
Yeah, I tried that.  The bullets still appeared in the front, though. I think they're both referring to the same thing.

TheIndieStation

  • *
  • Posts: 2263
Front/Back has nothing to do with positions, but with the order of which they are being drawn on screen. In order to make the bullets spawn in the center and front of the ship, use this:

create bullets at x: X of self y: Y of self

or if the bullets image is wider the the ship

create bullets at x: X-center of self y: Y of self
set X to X of last created actor - half width of last created actor for last creater actor

If you want them to be a bit in front so the bullets start exactly in front of the guns, do something like this:
create bullets at x: X of self y: Y of self - offset (where offset is a number you have to play around with to make it look perfect).

VoidShard

  • Posts: 81
I don't see any problem with your code, but here are some things you might try.

Is it that you want the bullets to appear north of the player (above)? If so, here are a few things you might want to check:
1. Is the player's position relative to screen? If so, is the scene larger than the screen? The player's position could be read off of the screen coordinates and the bullets generated in the scene coordinates.
2. Create Player Bullets at (x-center of self - half-width of player bullets)

If you want the bullets to appear in front of your player (graphically over) generate the bullets and do this.
Have a block that sets the z-coordinate of the last created actor within the layer to the bottom right after the bullet is created.

Also, a small suggestion: If you're planning on making a really good shooter, you might want to look at trigonometry for calculating where bullets should appear. (and making it more bullet hell-ish than space invaders-ish)
I hope this helps.