How to program a parry mechanic?

In my game, the player is standing still and projectiles are fired In their direction. When the projectile collides, the player needs to be either not blocking, blocking, or blocking within the parry window. I have 2 major problems that need to be addressed

  • Prevent all attacks from being parried by spamming block

  • Align with the players animations

Without an attacker to signal an attack and then create a parry window, this has been hard to implement. I currently have 2 solutions in mind for a character whose block animation takes 0.3 seconds to complete.

time delay at the beginning of the block:

  • block button clicked (0s)

  • won’t parry projectile (0s - 0.05s)

  • will parry(0.05s - 0.3s)

time delay after block button released before player can input:

  • block button released

  • can’t input block for 0.05s

I would really appreciate any ideas regarding this matter. Especially on how games like sekiro and ronin the last samurai(mobile game) balance smooth animations/input while preventing parry spam.

TLDR: How to program a parry mechanic for projectile attacks that collide with the player while preventing parry spam.

I think it would really be helpful to not tie yourself to the animations unless absolutely necessary.
Write core logic, make animations react to logic and ensure block/parry animation is played when you are infact blocking/parrying.

If we are talking about specific animation logic, it depends on a game, but I would make separate animator layer with upper-body avatar mask and added empty state, parry state, block state moved from one to another acording to animator parameters IsBlock and IsParry which are set according to character state.
If your character is static while parrying you can use same animator layer.

Most games have parry recovery, just make parry cooldown timer and set it to 0.5s-1s upon exiting parry/block.

1 Like

Parry recovery, a delay in the parry start itself (like to raise your shield and swipe it outwards), or even use up some stamina to give the parry a real game cost… quite a few ways to inhibit parry spamming.

Whatever you do, don’t fall into the trap of coroutines if you don’t truly understand how they work: do this kinda stuff with nice simple float timers or else you will soon be in coroutine hell and unsure of why things aren’t going well.

Agreed if you’re a solo developer, doing all the animations yourself. I find it easier to make a table of times and states to go with my animations.

But if you’re on a team and another guy is making the animations, you want to expose animation-driven timing functionality, probably by AnimationEvents, so the animator can adjust timing. Of course this puts the animator “in the loop” as far as game difficulty and play, meaning they can fundamentally change / break the mechanic they are setting stuff up for. This is just the double-edged sword of engineering and delegating tasks out. :slight_smile:

@Kurt-Dekker @Lekret
Thanks for the insight. It seems that each option has its own fallbacks, and I’ll just have to decide on one. For example:

  • Parry Recovery / Delay in Parry start: Player can’t parry multiple projectiles flying close together in a harder difficulty.
  • Use up stamina: I was planning on a parry actually restoring posture.

Also, my comment about aligning with player animations was not so much about being perfect, just something simple that matches the parry window. Probably an unnecessary addition as I was only worried about core logic.

(Probably should ask this elsewhere, but do I have to @ you guys for you to see my reply if it’s not directed towards you)