Limiting number of shots at one time

0 favourites
  • 12 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hello

    I am making a game where the player shoots missiles at falling asteroids. I have it set up so when the player presses the spacebar a missile is fired.

    I want to have it so the player can only have 3 missiles on the game screen at once.

    I have set a local variable called "shot" on the missle object. I have the value of "shot" to increase vy 1 each time the space bar is pressed and the value "shot" decreases each time the missile goes beyond the playing are.

    How do I check to see if the value of "shot" is less than three when pressing the space bar before the missile is created?

    Thanks for any help.

  • On the press space bar event you add another condition next to it (blocks can contain multiple conditions) which is shot.variable < 3. This is found under the player object's conditions and then compare instance variable.

  • Thank you for your help.

    This is what I have done but it is not working. Any suggestions?

  • The variable should be on the single object that is shooting such as the player object, not on the missile which is being created. Or you can use a global variable which is fine and maybe better.

  • LionZ thank you for your help.

    I tried with a global variable and it still is not limiting the shots.

    Here is my event sheet. Any suggestions?

  • On the action you need to add 1 to the global variable 'shot', you are increasing the wrong variable.

  • Thank you again.

    I think this is correct but it is limiting the number of active shots to 5 instead of 3

  • You can just check this:

    system -> compare two variables -> missile.count < 3

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thankyou Headbang Games

    I tried it but still is not working.

    Any suggestion?

  • Thank you again.

    I think this is correct but it is limiting the number of active shots to 5 instead of 3

    I don't think so? What were you using to verify that it's 5 shots. The variable can't go over 3.

  • Thankyou Headbang Games

    I tried it but still is not working.

    Any suggestion?

    I meant you don't even need the variable, user "compare two values", where the first value is missile.count (that's how many missile instances are currently existing in runtime).

    Using a variable should also work, but you don't really need it. If you're using a variable, make sure you destroy the missiles in every event and reduce the variable number (outside of bounds, hitting something, or whatever other events you have for the missiles).

  • Thank you both-

    I figured out the problem.

    When I first was trying this out I made a local variable called "shot" with the missel.

    I then made a global variable called shot but did not delete the local variable.

    It works now plus I learned so additional skills.

    Thanks again.

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