Jump to content


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 "weapon.fire()" 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.blastSound.play()},this);

		return weapon;

this.ship = this.add.sprite(this.world.centerX, this.world.centerY +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.

Link to comment
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.

Link to comment
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.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...