• Question
  • how do i make it so my object shoots out a projectile on command

ok so i've been trying to find a way that it would shoot out a projectile on command.
what i mean by this is that, my game uses a fire rate system created by @Letti42, you have to hold down the key to make it shoot (you can't just press it once or else it wont shoot), so i thought about a solution. as it turns out i dont know how to make it, that's why im asking.
(ignore the functions that are not relating to the gun's shooting)

 var timer;
  function startShooting(fireRate){
  fireRate = fireRateEach;
  if(timer)return;
  timer = setInterval(function(){
    createBullets();
    loseBullet();
    playSound("gunShot.mp3", false);
  }, fireRate);
 }

 function stopShooting(){
  setTimeout(function() {
    clearInterval(timer);
     timer = 0;
  }, gunWentDown);
 }

 function createBullets(){
   bullet = createSprite(player.x, player.y);
   bullet.setAnimation("bullet");
   bullets.add(bullet);
   bullet.setSpeedAndDirection(8, player.rotation);
   bullet.lifetime = 100;
 }

 function shooting() {
   if (keyDown("space") || keyWentDown("space")) {
      startShooting();
   }
   if (keyWentUp("space") || stage != "game") {
     stopShooting();
   }
 }

i wonder how you saw this letti

oh yeah btw i did find a solution but it is spammable (which means the fire rate doesn't apply to those bullets)

That's weird, it worked for my version..

    Letti42 it kinda didnt. you have to hold down the space bar to shoot

    Do you want it so that they can just toggle the shooting, like on and off, or have the player hold it down?

      Letti42 i want it so like the can hold it down like an automatic and do semi-auto (semi-auto is basically you just have to press the spacebar once)

      Set danmaku color
      Set danmaku type
      0:00 / 0:00
      Speed
      Loop
      Show danmaku
      Unlimited danmaku
      Opacity for danmaku
      0.5
      0.75
      Normal
      1.25
      1.5
      2
      [x]
      Player version
      Player FPS
      Video type
      Video url
      Video resolution
      Video duration
      Video load failed

      ackvonhuelio mine is with guns and does not need proper charging to shoot (only thing closet to charging is when you have to reload, and if you even have to reload, it shoots instantly if the mechanism activates. no charge required)

        Chat