1
\$\begingroup\$

So working on a 2d fighting game and wondering whats a good method for detecting punch collision. Ive got a few questions on how to implement the attack stuff. Im using box2d (and Libgdx) for the movement and collision detection.

  1. Best way to do punch and detection? Currently thinking of creating a fixture on the body and destroying it after a little time with a Timer

  2. How to do a multipunch combo, basically if they hit the button 3 times in a row it does a combo attack? Think creating a variable that gets added +1 when they hit the button and a timer resets it back to 0 after a certain amount of time

  3. Prevent attacks during the attack animation to prevent button jamming? Currently using state status so need to figure out the best way to change the state to/from attacking

\$\endgroup\$
1
  • \$\begingroup\$ It sounds like you have candidate solutions for all of your questions, and they sound like they'd work. Have you tried prototyping the game based on these ideas? If you run into any trouble or undesired behaviour in the process, asking about that concrete problem generally leads to more focused & constructive answers \$\endgroup\$ – DMGregory Mar 6 '18 at 12:32
1
\$\begingroup\$

I assume this is a street fighter like game so I'm not sure why you would need to destroy a fixture after a set period unless you have parts of the fighter that get destroyed during the fight but this is what I would do:

  1. I would have a sensor fixture/s on each player's body to register hits and sensors for each hand. This would allow you to register attacks without affecting moving/animations.

  2. Have a super class called something like Attack which has value for length of attack (attackLength),a value for next attack (comboAttack), and a list of valid combo Attacks(attackList). The attack length could then be used to determine when the attack has finished and to determine if the next attack was triggered in time to be considered a combo. Then if the combo is in the valid list add it to the comboAttack. When the attack is finished check if the comboAttack variable has a combo if so do that combo move.

  3. As stated in point 2 using a variable like attackLength would allow you to determine whether an attack was ongoing or completed.

\$\endgroup\$
1
  • \$\begingroup\$ ok this is what I was thinking, i guess making the sensors once would work better then creating/destroying them \$\endgroup\$ – DRing Mar 7 '18 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.