Bullet mechanic

I am trying to figure out how to get a moving enemy object to fire a bullet at the player object only when the enemy is "facing" the player.

Does anyone have a method for this, or can point me towards a tutorial/solution?

Thank you

There are a number of ways to do this depending on the shape of your pieces and game action.

One way is to use collision detection. Have an invisible triangle or rectangle extending from the front of your enemy object as a physics object and "fire" when a collision occurs between this invisible object and the player.

Another option is to track the facing of the enemy in a master game loop by getting the current rotation of the enemy and compare it to the player.objectBounds screen coordinates to trigger a "fire", if the X or Y coordinates of the enemy fall within the bounds of the player object.

-David

Thanks for the reply.

I am not quite skilled enough to understand the exact method in the latter of your post.

The former part will not work since corona does not allow you to rotate objects by a selected reference point in their physics engine. Are you aware if there is a fix for this?

Thanks again.

views:1341 update:2011/12/1 20:56:45
corona forums © 2003-2011