Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
How to kill bullet after a certain of distance?

How to kill bullet after a certain amount of time, or certain amount of distance ? I'm using JavaScript and Phaser 3.

if (keyA.isDown && time > lastFired || isDown && time > lastFired) {
          
            var bullet = bullets.create(player.x , player.y, 'bullet');
            
            bullet.setVelocity( -800, 0);
            lastFired = time + 90;

        }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If it should be after some time, you could do something like this. (here some more details from the Docs: from the Docs )

But to be honest I don't know, if this would impact the performance, or not.

 ...  
// the 500 ist the timeout in ms
this.time.delayedCall(500, () => bullet.destroy();  
....
(add this line after creating the bullet)

Or you cout use a time event

this.time.addEvent({
    delay: 500,
    callback: ()=>{
        bullet.destroy()
    },
    loop: false
});

for destroying by distance: depending if it is one bullet or many. you could add the bullet to a group and check the distance in the update function, and it its too far you detroy it/them.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!