Get An Enemy To Fire Bullets at 8 Angles?

0 favourites
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • Hi,

    I have a script set up so that, when Space is pressed, an enemy called a Boombox in my game will be destroyed and release bullets in 8 different directions, at 45 degree angles (e.g. 0, 45, 90 and so on). However, the enemy just fires lots of bullets down rather than firing them in different directions. I know that there are lots being fired because of the debugger, but they are all heading in the same direction.

    Here is my code:

    <img src="" border="0">

    (If the picture doesn't work, here it is)

    Can anybody help me?

    Thank you!

  • Using sub-events, you make sure only the bullet in the event above is referenced.

    <img src="" border="0" />

  • and another function to do basically the same thing

    Function to fire (random ?) number of bullets around player

  • OrangeFlash81,

    Just so you understand why your method didn't work: when you use a spawn, the spawning object's attributes are inherited by the created object. This includes the object's angle (so, on your example, I'm guessing that the Boombox was set at 90 degrees for all of the bullets to travel downwards). This spawn action overrides any immediately subsequent attempts to change these inherited attributes. Son any attempt to change an angle after a spawn will never work.

    A crazy alternative method would be to create 8 invisible gun objects and pin them to the player, with each one set at 45 deg to the last. Then, when you shoot, you just have one line commanding "gun: spawn bullet" - the event system will select all guns and spawn all of the bullets for you.

    Hope this helps!

  • This spawn action overrides any immediately subsequent attempts to change these inherited attributes. Son any attempt to change an angle after a spawn will never work.

    Are you sure this is right ?

  • RamPackWobble,

    Err - no! My mistake - it appears that I need to go back to the manual (again!!). I have also encountered OrangeFlash81 's problem before and just assumed that this was the case (a system create object never causes the non-setting of attributes as shown in the OP).

  • Try this instead:

    +on "BoomboxExplodeNow"

    +For "" from 0 to 7

    -Create [StandardEnemyBullet]

    -Set angle of motion to loopindex*45 degrees

  • Colludium OrangeFlash81 the reason it doesn't work in the first post is because every item spawned is added to the current object selection. So every "Set bullet angle" is applied to all the bullets in the current selection, and this is why the same angle is on every bullet at the end.

    LittleStain had it right, it should work this way, even if it's not that beautiful. MadFactory solution is nicer and will also work (as the new bullet is created inside the loop, thus not added to the current object selection on next loop index).

  • As we have not seen the capx I am going to make an assumption - and that assumption is that the bullets (when spawned) have zero speed. A bullet with zero speed can not have any angle of motion except 0. A bullet travelling at an angle of 45 degrees that is stopped (speed) and then restarted will travel at 0 degrees.

    (example of bullet "changing direction" because of zero speed)

    So if you are spawning your bullets with zero speed and then setting the angle of motion and then altering the speed then the bullets will travel at 0 degrees!

    But like I said - all assumption (and yes I am waiting fot the "Silence of the lambs" quote <img src="smileys/smiley1.gif" border="0" align="middle"> )

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Did anyone even look at my original capx ? <img src="smileys/smiley19.gif" border="0" align="middle">

    <img src="" border="0">

    and while I am at it (spitting out my dummy and stamping around !) <img src="smileys/smiley1.gif" border="0" align="middle">

    <img src="" border="0">

    works !

    None working function that works

    Time for a coffee and my medications I think !

  • RamPackWobble I looked at it. One of your function was correct I think, the one with a loop, but you didn't start at 0 degrees, because loopindex starts at 1. Shouldn't change much though. And ok for using random, but random(360) ? ^^ lots of bullets :p

    Also, thanks for the point on 0 speed bullets resetting their angle, I didn't know this !

  • Guizmus

    I know my solution wasn't pretty, it wasn't meant to be.

    It shows the basics in creating and subsequently adressing the created object.

    Even though sometimes it can be done directly in the actions that follow, using the subevent makes it much clearer what is intended and makes it more readable.

    I would use a loop or function for this particular case, but for "construct-newbies", I'd rather give them something they can try to understand and re-use.

  • Using sub-events, you make sure only the bullet in the event above is referenced.


    Just tried this, it did the same thing that my script was doing. Thanks for the suggestion though. About to try MadFactory's suggestion.

  • Strange..

    The picture I posted is a screenshot of the eventsheet of a capx that worked perfectly. Are you sure you haven't got conflicting events anywhere else?

  • OKAY. I was doing the most stupid thing. In the world. Turns out LittleStain's solution does actually work. To fix a little bug that I had in creation, I made this event!!

    <img src="" border="0" />

    Whoops... Thanks for your help anyway!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)