Jump to content

How have you implemented something like a "detection range"?


David
 Share

Recommended Posts

I have turrets that need to react only to things within a certain distance.  Of course, this could be done simply by checking the distance of every targetable object with every turret, but considering the amount of things I want to have on screen, the number of checks could get quite high.

 

My current implementation uses an invisible "detection range" sprite with a custom collision processor in order to take advantage of the quad tree

 

I'm sure this isn't a unique problem so I wanted to see how others handled this.  Did you go the collision route?  Did you just do a simple distance check against all objects without any real performance issues?  Did you do something else that I'm not thinking of?

Link to comment
Share on other sites

Use distanceBetween. It is(was) in phaser because I used it myself in a test project.

I'm pretty certain this should still be in phaser too.

Load up phaser in your editor of choice and search for distanceBetween. I'm not sure if its in arcade/P2 or ninja but it might still be there.

I say might because I built that game in 1.1.4 phaser and use distanceBetween myself.

Link to comment
Share on other sites

Phaser.Physics.Arcade.distanceBetween still exists, however it seems to be a bit of a holdover from old versions what I can see.

 

Phaser.Point.distance also does the same, except it explicitly takes Phaser.Point objects (if you're using TypeScript to enforce types) like so:

turret.reactionDistance = 50; // distance in pixelsif (Phaser.Point.distance(turret.position, target.position) <= turret.reactionDistance) {  turret.react();}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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