Jump to content

How to make bullets stop at a certain point??

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