Jump to content

Drewrg
 Share

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.scale.setTo(0.22);
		this.ship.angle = -90;
		game.physics.arcade.enable(this.ship);
		this.ship.body.drag.set(70);
		this.ship.body.maxVelocity.set(220);
 		
 		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.

output_QuXETQ.gif

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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