Any ideas why my code is spawning a 'shadow bullet'

Hi there this is my first post(I made this account purely to get help with this, and probelbly more in the comeing weeks). I have the code set up and running to allow my bullets to fire however when I do I get a bullet shooting along the path it is meant to and a bullet that stays in place for until the bullet instance gets destoryed. I can’t figure out why. Any level of input would be very much apperciated.

Sorry if I have posted this incorrectly it my first time posting.

Within the Scene:

  create() {
    //-unrelated code-
    this.projectiles = this.physics.add.group({
      classType: Bullet,
      maxSize: 1,
      runChildUpdate: true,
    });
  }

  update(time, delta) {
    if (this.mouse.isDown && time > gameSetting.lastFired) {
      if (gameSetting.playerIsDashing == true) {
        return;
      } else {
        this.shoot(time);
      }
    }
  }

  shoot() {
    let projectile = this.projectiles.get();

    if (projectile) {
      var bullet = new Bullet(this);
    }
  }

Now the bullet class:

class Bullet extends Phaser.Physics.Arcade.Sprite {
  constructor(scene, x, y) {
    super(scene, x, y, "bullet");

    this.spawn = 0;
    this.speed = 500;
    this.setActive(true);
    this.setVisible(true);
    scene.add.existing(this);
    this.play("bullet_anim");
    scene.physics.world.enableBody(this);
    this.setRotation(scene.player.rotation);
    this.x = scene.player.x + 20 * Math.cos(this.rotation);
    this.y = scene.player.y + 20 * Math.sin(this.rotation);
    this.body.setVelocityX(this.speed * Math.cos((Math.PI * this.angle) / 180));
    this.body.setVelocityY(this.speed * Math.sin((Math.PI * this.angle) / 180));
    //scene.projectiles.add(this);
  }

  update(time, delta) {
    console.log("this is working");

    this.spawn += delta;

    if (this.spawn > 1000) {
      this.destroy(true);
    }
  }
}

:wave:

I think one is projectile and one is bullet. If you want to use this.projectiles (physics group) then remove

var bullet = new Bullet(this);

Remove these from the Bullet constructor and put them in a new method, e.g. Bullet#shoot(). Then call it as projectile.shoot().

Hi there thanks for the response. I was in the process of writing a post about how this was throwing errors back at me but I was not sure what I had done wrong. I forgot to refernece the scene in the method.Coding does nto come easy to me.
I have another question, if your willing to awnser(don’t worry if not you have already helped me). I would like the bullets that are spawned to bounce of the edge of the map. How would I do this?

In add.group({…}) add collideWorldBounds: true, bounceX: 1, bounceY: 1.

A post was split to a new topic: How would I create collisions between these and the bullets