nicwins

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

7 posts in this topic

Because my bullets are killed via a timer, sometimes the timed intervals differ due to acceleration etc.

 

Can you kill bullets after they have travelled x amount of pixels??

Share this post


Link to post
Share on other sites

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.

Share this post


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

Share this post


Link to post
Share on other sites

@Milton, what is the syntax for using the lifespan? is it milliseconds?

 

@samid737, I'm going to have a go at these methods tomorrow, will let you know how I go.

 

Thanks

Share this post


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

Share this post


Link to post
Share on other sites
44 minutes ago, nicwins said:

@Milton, what is the syntax for using the lifespan? is it milliseconds?

Yes.

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

  • Recently Browsing   0 members

    No registered users viewing this page.