Getting Weapon Bullets to bounce off World Bounds?

I have some problems with getting bullets to bounce off of the world bounds.
I’ve managed to make the bullets collide with the world bounds, but they do not bounce.
I have no problem with making a normal sprite bounce off the world with: sprite.body.bounce.set(1);
but this does not work with bullets.

bossweapon = game.add.weapon(100, ‘spacebullet’);
bossweapon.bulletSpeed = 300;
bossweapon.fireRate = 20;
bossweapon.bulletAngleVariance = 20;
bossweapon.bulletCollideWorldBounds = true;
bossweapon.bulletKillType = Phaser.Weapon.KILL_LIFESPAN;
bossweapon.bulletLifespan = 2000;
bossweapon.trackSprite(boss, 0, 0, false);

However, writing “bossweapon.body.bounce.set(1);” or anything like that, has no effect.

Any suggestions?

Maybe the bullets are not Sprites, so they lack a “bounce” property. You can check the API.

bossweapon.body.bounce.set(1)

Phaser.Weapon has no body property so that will error. Make sure you have the console open.

bossweapon.bullets.setAll('body.bounce.x', 1); // etc.
1 Like

Yeah, I understand. Which is why I also had trouble getting the bullets to collide with the world, until I just
randomly typed in the correct code that made it work. Something I unfortunately couldn’t also do for the bounce code.

But thanks a lot! It works perfectly now. :slight_smile: