How to program my attack logic

Hello,

So I’m a new developer and I cannot find anywhere how is the attack logic programmed in games as a whole.I cannot even find for one specific game how it is done.Nevertheless, this is my prototype on the image and my question is how can I program the following : when the button with the fist is clicked the knight launches his attack animation and destroys enemy in front of him. Now I obviously can’t put collision detection on the sword so any ideas how it’s gonna be done ?   

Regards

enterm

This question requires a LOT more detail from you to get a useful answer.  You could totally add a physics body to your knight and use a sprite listener with it.  When you detect a certain frame is active (see here) you can pay attention to any collisions you see from the physics body.

Take a look at this video https://www.youtube.com/watch?v=SCe7ZMXh02I

Are you interest by some information about my attack motor? (Stronghold)

@Supertapp Hey. Your idea seems to hypothetically fit. It will take me some time to implement it and  I’ll  write my results here when I’m done. Thank you.

@remiduchalard Hey man , your attack motor seems really interesting. I was about to write you a PM but then i thought “Hey, why not ask in the topic. It can be helpful to others”.So - hell yeah,  I’m interested. I hope it’s no problem to share the info here.

Regards to both of you

enterm

I will try to sum up my engine (my engine is 4000lines):

All unit are in a table. Good guy have negative key (-1,-2…) and bad guy have positive.(optimization when you are looking for unit)

All unit have enterframe listener.

I don’t do calcul every enterframe because it s useless. The frequence of calcul depend of if the unit fast(mp/h)

Calcul:

   - Find all unit who are not far of him (the distance depend of the fast)

   - For moving unit:

      - There is unit who are looking for fight and there is unit who don’t want to fight.

           - Unit who don’t want to fight, if the unit your are testing want to fight, calculate if there is enought fast to catch him (depend of the fast and direction of the unit)

   - For unit who are not moving

       - If the unit is already fighting go to fight him if there is no one free

       - Go to fight him (he is waiting for it :wink: )

  - Choose the closer unit

Do you understand?(my english is not good) Do you need more details?

This question requires a LOT more detail from you to get a useful answer.  You could totally add a physics body to your knight and use a sprite listener with it.  When you detect a certain frame is active (see here) you can pay attention to any collisions you see from the physics body.

Take a look at this video https://www.youtube.com/watch?v=SCe7ZMXh02I

Are you interest by some information about my attack motor? (Stronghold)

@Supertapp Hey. Your idea seems to hypothetically fit. It will take me some time to implement it and  I’ll  write my results here when I’m done. Thank you.

@remiduchalard Hey man , your attack motor seems really interesting. I was about to write you a PM but then i thought “Hey, why not ask in the topic. It can be helpful to others”.So - hell yeah,  I’m interested. I hope it’s no problem to share the info here.

Regards to both of you

enterm

I will try to sum up my engine (my engine is 4000lines):

All unit are in a table. Good guy have negative key (-1,-2…) and bad guy have positive.(optimization when you are looking for unit)

All unit have enterframe listener.

I don’t do calcul every enterframe because it s useless. The frequence of calcul depend of if the unit fast(mp/h)

Calcul:

   - Find all unit who are not far of him (the distance depend of the fast)

   - For moving unit:

      - There is unit who are looking for fight and there is unit who don’t want to fight.

           - Unit who don’t want to fight, if the unit your are testing want to fight, calculate if there is enought fast to catch him (depend of the fast and direction of the unit)

   - For unit who are not moving

       - If the unit is already fighting go to fight him if there is no one free

       - Go to fight him (he is waiting for it :wink: )

  - Choose the closer unit

Do you understand?(my english is not good) Do you need more details?