Sign in to follow this  

Phaser JS Weapon plugin

Recommended Posts

Hello! I'm having a hell of a time trying figure out how to change Phaser Weapon plugins bullet speed after it's been shot.
I also set "weapon.bulletSpeed" negative value, because by default it was going in opposite direction.

I attached weapon to a spaceship sprite, but on "" bullet goes backwards.

Weapon definition.

addWeapon: function(target) {
		var weapon;

		var weapon;

		weapon = game.add.weapon(100, 'bullet');
		weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
		weapon.bulletAngleOffset = 90;
		weapon.bulletSpeed = 5;
		weapon.trackSprite(target, (this.ship.height), 0);
		weapon.trackRotation = true;
		weapon.fireRate = 200;
		weapon.bulletRotateToVelocity = false;
		weapon.onFire.add(function() {},this);

		return weapon;

this.ship = this.add.sprite(, +300, 'ship');
		this.ship.anchor.setTo(0.5, 0.5);
		this.ship.angle = -90;
 		this.weapon = this.addWeapon(this.ship);

I am trying to

  1. set the direction of the bullet to opposite, so I don't have to set bulletSpeed to negative value.
  2. change every bullets anchor.
  3. change the speed of particular bullet after it's been shot.

It would be grate to hear any suggestion.

Тhank you in advance.

Share this post

Link to post
Share on other sites

I don't know exactly what's wrong, but maybe I can help with some little bits?

Your listener to the onFire signal will receive two arguments: the weapon that fired and the bullet that was successfully fired. You could change the bullet's speed in there for the bullet that was just fired.

If you need to change all the bullets' anchors no matter what, though, you can say "weapon.bullets.forEach" since "weapon.bullets" is a group.

You have both "trackRotation = true" and "fireAngle = 60". That fireAngle is going to be ignored because the weapon is tracking the sprite's rotation.

I don't know about the bullet going in the opposite direction. I *suspect* that your tracked sprite isn't pointing the way you think it's pointing, i.e. your graphic is drawn with your sprite facing left but Phaser's angle is set to 0 which is pointing to the right. Just a guess, though.

Share this post

Link to post
Share on other sites

Thank you for reply, I've rotated the actual png image itself, and that solved the wrong direction of fire.

But anyway I still can't adjust speed and anchor of particular bullets.

As you can see in gif, the position of weapon is correct, but bullets anchor point is incorrect.


Share this post

Link to post
Share on other sites

hi @Drewrg


method says:

* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.

that means you can do:

var your_bullet =;

and get Phaser.Bullet sprite that was shoot and change their speed.



Share this post

Link to post
Share on other sites

Hello @LuizOtavio I used. 

this.weapon.bullets.setAll('anchor.y', 1);

This is worked for me so far.

For the bullet speed, I am using 

Phaser.Physics.arcade.overlap(bulletsGroup, target, function);

which is returning the bullet that were collided.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.