Best way to HIT



I'm creating test project where is Player and Enemy. But just thinking what would be best way to hit with fist? It should work like this:
- Press SPACE --> Players hand shows up (and there would be HitBox that "hurts" enemy
- After hitting hand goes back to "Standby state" waiting next Space pressing

And off course enemy should hit also when it comes near player but I'm not that far yet (I only have objPLAYER)

But just asking what would be the best way to code this hitting and then make hand to go It's normal state...?


Friendly Tyrant
Forum Staff
You would want to use a "state machine". This is basically having a "state" variable that is then checked in the STEP event of the instance to make the object perform different tasks depending on the state. So, for example, with this you would have maybe an "input" state and a "hit" state. In the "input" state you wait for the player to do something, like press a key. When the player does, you change to the "hit" state and then perform the hit action. When that finishes you would go back to the "input" state again... this is pretty much the most common way to do this kind of thing, and once you get it working for the player, it's really easy to transfer the same basic code to the enemy for AI. Check out this basic State Machine tutorial I wrote a while back to get an idea of how this kind of system works: