Jump to content

How to make bullets stop at a certain point??


Bubbles
 Share

Recommended Posts

Hey everyone!

So I'm pretty new to Phaser and I'm having a hard time making the player's bullets stop at a certain point (e.g killing the projectile at around 30px after its original position, etc). I want the player to have a limited projectile range and I'm just wondering how you can implement that because all my attempts of trying to figure it out have failed so far, so I'm seeking help from you guys... Thanks for any advise!

Edited by Bubbles
accidentally submitted an incomplete message
Link to comment
Share on other sites

If you want to calculate how far something is away from your player you can use game.math.distance(x1, y1, x2, y2)
 

so you would use something like

if (game.math.distance(x1, y1, x2, y2) > 30) ){

   // destroy the object

}

 

x1 and y1 are the coords of your player

x2 and y2 the coords of the object you are comparing

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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