Jump to content

Possible to kill bullet after it has travelled a certain distance?


nicwins
 Share

Recommended Posts

Save the starting point and then get the distance it travelled.

Use the euclidian distance for this:

dist((x, y), (a, b)) = (x - a)² + (y - b)²

 

In your case this would be:

Math.sqrt(Math.pow(start.x - now.x, 2) + Math.pow(start.y - now.y, 2))

I am not sure about the formula, looks kinda off Oo.

But it should be like this.

Link to comment
Share on other sites

 

You could do manual distance checking just like @SeelenGeier suggested if you have your own weapon system with varying bullet accelerations. If you are using Phaser.weapon, you could use the bulletKillDistance property:

http://phaser.io/docs/2.6.2/Phaser.Weapon.html#bulletKillDistance

If your game/world allows it, you could also make a dummy collision body that serves as a wall that automatically destroys bullet oncollision via callbacks.

Link to comment
Share on other sites

I don't use the weapon plugin, as it is just one enemy.

The main problem is the initial timing from when it goes from creating bullets to getting from the pool of bullets - so the first bullets seem to last longer than the pooled bullets...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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