Ideas for range detection

I recently asked a question related to this but I realize that physics.queryRegion is not a good option. What else can I do here? How would I get the physics bodies within a specific range?

A kinematic body as a sensor was mentioned. So would I create an invisible object that updates with the ship’s movement, create a kinematic body for it, and then use that as a sensor?

What’s the question?

Why is queryRegion() not a good option?

Well, because I would somehow have to have the physics.queryRegion moving along with the object and to make a physics.queryRegion move would take constant creation and removal.

physics.queryRegion doesn’t require creating any new display objects and/or physics bodies (and so also doesn’t require their removal)

Regardless of how you go about this, there will need to be a list of objects that you care about the distance from and every time the player moves, you have to iterate over that list and check the distances.  You can have your own table of objects and an enterFrame listener (or have it tied to your move somehow) and loop over the objects, compute the distance using the Pythagorean theorem.  physics.queryRegion() is likely going to do the same thing. It’s a matter of you doing the work or letting an API do the work for you.

Of course, you can always do some test cases and see if you’re own list management may be more efficient. Obviously, if you’re not using physics, using physics just to get to physics.queryRegion() doesn’t make sense.

Rob

@Rob:  probably safe to assume he’s already using physics since considering both queryRegion() and a kinematic sensor attached to his ship’s body.  But apparently both of those physics-based approaches are ruled out, perhaps the “what else” means he IS seeking the manually-iterate-a-list-of-objects-and-calc-distance approach?  Or maybe he’s just asking “how do I make a sensor?”  Unclear, I’m now with @horacebury and don’t understand the question.  :D  @sdktester15:  rephrase please

Right now, I am interested in Rob’s approach. I have pushed aside the kinematic body and sensor approach. I am just going to make a small project to test this.

Note: This thread is an extension of this earlier discussion: https://forums.coronalabs.com/topic/70905-is-it-possible-to-make-a-physicsqueryregion-move/#entry370244

What’s the question?

Why is queryRegion() not a good option?

Well, because I would somehow have to have the physics.queryRegion moving along with the object and to make a physics.queryRegion move would take constant creation and removal.

physics.queryRegion doesn’t require creating any new display objects and/or physics bodies (and so also doesn’t require their removal)

Regardless of how you go about this, there will need to be a list of objects that you care about the distance from and every time the player moves, you have to iterate over that list and check the distances.  You can have your own table of objects and an enterFrame listener (or have it tied to your move somehow) and loop over the objects, compute the distance using the Pythagorean theorem.  physics.queryRegion() is likely going to do the same thing. It’s a matter of you doing the work or letting an API do the work for you.

Of course, you can always do some test cases and see if you’re own list management may be more efficient. Obviously, if you’re not using physics, using physics just to get to physics.queryRegion() doesn’t make sense.

Rob

@Rob:  probably safe to assume he’s already using physics since considering both queryRegion() and a kinematic sensor attached to his ship’s body.  But apparently both of those physics-based approaches are ruled out, perhaps the “what else” means he IS seeking the manually-iterate-a-list-of-objects-and-calc-distance approach?  Or maybe he’s just asking “how do I make a sensor?”  Unclear, I’m now with @horacebury and don’t understand the question.  :D  @sdktester15:  rephrase please

Right now, I am interested in Rob’s approach. I have pushed aside the kinematic body and sensor approach. I am just going to make a small project to test this.

Note: This thread is an extension of this earlier discussion: https://forums.coronalabs.com/topic/70905-is-it-possible-to-make-a-physicsqueryregion-move/#entry370244