How to detect object proximity?

I have an object (an enemy) that I want to have it jump up when the player is above it in a sidescroling game.

But because it’s not a collision, I can’t think of the logic of how to solve this.

I know I could loop through every enemy in the game each game loop, and compare positions (if player.x ~= enemy.x ) but that doesn’t sound very efficient.

Any thoughts? Is there something native in Corona I’m not remembering? My Googling has turned up mostly GPS proximity stuff.

Hi @Zenoxio,

I would suggest adding an additional larger radial physics body (sensor type) to the player, and detect collision between only that element and other objects (enemies, I assume). When an enemy collides with the sensor element, make it do whatever it needs to do… but remember to handle normal collision of the player using that element’s index too, because once you add an another element to a body, you’ll need to detect collisions based on element indices.

Hope this helps,

Brent

Hi @Zenoxio,

I would suggest adding an additional larger radial physics body (sensor type) to the player, and detect collision between only that element and other objects (enemies, I assume). When an enemy collides with the sensor element, make it do whatever it needs to do… but remember to handle normal collision of the player using that element’s index too, because once you add an another element to a body, you’ll need to detect collisions based on element indices.

Hope this helps,

Brent