0 Favourites

[Solved] Bullet Limit (Number of Bullets on Screen)

  • I want to have 4 Bullets (Projectiles) max on screen at one time. The Bullets destroy when it collides with any other object.

    What is the best way to set a Bullet Limit?

    My game is a Platform/Run 'n Gun.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Use a variable bulletTOTAL to track the number of bullets

    Each time you create/spawn a bullet add 1 to bulletTOTAL

    Each time you destroy a bullet minus 1 from bulletTOTAL

    Then use...

    Event -> Compare variable bulletTOTAL < 4

    Actions -> Create Bullet etc

  • The fun thing about Construct is that it keeps a count of the objects. First, make sure bullets are destroyed when out of layout.

    Then keep track, of many objects are on the screen. I typically assign some kind of global variable. NumberOfBulletsOnScreen = 0

    Now, when you press the space key (or fire key) count the number of objects on the screen. Number of bullets = bullets.Count

    '.Count' is appended after the object name to get the total number of that objects on the screen.

    For your conditions down "when space key is pressed (or whatever key is the fire key) AND NumberOfBulletsOnScreen < 0

    and the actions would be

    spawn new bullet

    NumberofBulletsOnScreen = bullets.count

    This will work because you will keep a constant track of the bullets on the screen every time you fire. The layout always starts it as 0 so it will always allow you to start firing. As you fire it will raise the number of bullets on the screen. When there are 4, it won't let you fire any more. But you need to make sure to keep track of the number of bullets on the screen when the bullets are destroyed too. So you need one more condition and action.

    Condition:

    Bullet-On Destroyed

    Action:

    NumberOfBulletsOnScreen = bullet.Count

    That will lower the variable and reset it as bullets are destroyed.

  • arontwose beat me to it with a simpler solution.

  • Even simpler,

    Add this to the shooting event:

    bullet.count < 4 (this is a "Compare two values" system event)

  • Thanks everyone!

    I ended up using what "7Soul" suggested.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Construct Limits
50 11,374
Jayjay's avatar
Jayjay
Unread hot topic
56 6,107
broknecho's avatar
broknecho
Unread hot topic
54 7,194
SamRock's avatar
SamRock