I'm working on player and enemy collision similar to something like Super Mario Bros; I want to ensure that the only way that the player can destroy an enemy is if they jump and land directly on top of them.
Right now, I'm spawning enemies and then having them spawn a 1px high sprite which matches their width to act as hit detection from above. This is then pinned to the top of the enemy sprite. If the player touches this line whilst falling, the intention is that it will destroy the associated enemy that it's pinned to. The problem I have is that it currently destroys all instances of enemies that are on the screen. Is there a way to only destroy the enemy attached to the line sprite that the player hits or a more elegant solution to this problem?
Thanks for your help!