Random bullet direction.

This forum is currently in read-only mode.
  • Hello there. This might me a little bit of a newbie question but I figured I'll ask for help.

    So here I am trying to create a basic top down shooter. However I'm having trouble getting the enemy to shoot In a random direction. I want them to shoot In front of them - like this ugly paint drawing can illustrate.

    <img src="http://filesmelt.com/dl/direction.png">

    However I can only get them to shoot straight.

    An "always" and " "set angle" event obliviously don't work.

    Then I tried to set it to the "X millisecond, spawn a bullet" event but that only made a few fly in different directions.

    I'm at your mercy. Please help me!

  • Assuming that your bullets have Bullet behaviour, you can do the following:

    +Every 100 ms

    BigBadMeanGuy: Spawn Bullet

    Bullet: set angle to BigBadMeanGuy.Angle - 45 + random(90)

    They will fire randomly within the 90 degree cone in front of them.

  • That's what I also thought. But they just shoot straight for some reason.

    <img src="http://filesmelt.com/dl/donwork.png">

    That's what the Event looks like.

    Edit:

    Thanks to the "X.Angle - 45 + random(90)" command the they shoot in the correct angle. But it's only working on some enemies for some reason.

  • Hm, do you have any other events or behaviors affecting the bullets?

  • <img src="http://filesmelt.com/dl/enemy.png">

    That's the only thing I can think of.

    <img src="http://filesmelt.com/dl/work2.png">

    (place holder graphics)

    This is what it looks like in game.

  • Well, I can't tell what's making them fly straight without looking at the .cap.

  • http://dl.dropbox.com/u/3686062/shooter.cap

    feel free to take a look.

  • Add the following condition to the Every 800 ms event:

    For each enemy_1

    (you'll find it in System)

    This will ensure that each enemy is evaluated instead of all at once, thus in turn each bullet will shoot off into its own direction.

    Also, get rid of the enemy_bullet1_collition. Just check for collisions between bullets and player. (The collition sprites weren't moving at all, by the way. They stayed where they were spawned.)

    You might want to move the player_bullet action to the spawning event. It is pointless to change its angle to -90 every tick, once it is already facing that angle.

  • It worked!

    I could not thank you enough!

    You sure are a lifesaver!

  • Imagine that conditions are filters; all objects that pass through the filter are treated as one when you apply the action to them. The "For Each Object" condition instead executes the action for each individual object that passes the filter.

    I hope that helps clear it up

  • This also helped with a little tree-growing application I'm messing around with. I had the same problem, but instead of shooting bullets I was shooting... shoots.

    So thanks for that .

  • Ooo, tree growing sounds fun. I'm working on a platformer and will be requiring a forest background at some point. Randomized trees would be really cool. Any chance you can have a generated tree export to a png file?

  • Heh, that'd be cool, but since I've just been learning Construct for about a week, I haven't a clue how it would work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Haha, fair enough. How's the engine coming along? Any interesting results?

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