1
$\begingroup$

What I'm trying to achieve is some kind of python script or logic brick system that allows me to tap a key or button once and then through that action send out a burst of messages to an object that say shoots projectiles or something.

I've tried looking up ways to do this but I haven't found anything. How could this be achieved?

$\endgroup$

1 Answer 1

1
$\begingroup$

Burst Fire Example

This is a simple setup with only logic bricks to make a burst fire logic. Sure, you'll have to make your own to fit your project, but it contains the basic concepts for the timed events only by using game properties. The example file attached below.

On this example, we have the player object in the scene and a bullet object in a hidden layer.

Structure

In our player object we have two properties:

  • burst is the number of bullets left for each burst.
  • cooldown is the time interval between each burst.

Controller shoot

When we press Spacebar (sensor shoot), we check if:

  • shoot is pressed.
  • burst property equals to 0.
  • cooldown property is greater than 0.

These conditions mean that player pressed the shoot button and no burst fire is currently in progress, so we can proceed to a new burst fire. When these conditions are met, we:

  • Set the total number of bullets to fire to the property burst, using the actuator set_burst.

  • Set the cooldown time to a desired negative value using the actuator set_cooldown.

Controller burst

When the properties are changed through the shoot controller logic, we have the following behavior:

  • The sensor always is with pulse mode enabled, with a small skip value which means the interval between each shot.

  • The controller burst checks if always is active and burst is greater than 0.

When all these conditions are met, we:

  • Add a bullet to the scene.

  • Decrease an unity from the burst property

When the burst property reaches 0 and the cooldown property is greater than 0, we can repeat the process through the shoot controller.

enter image description here

Example file:

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .