Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question How to program a parry mechanic?

Discussion in 'Scripting' started by OOVUM, May 27, 2024.

  1. OOVUM

    OOVUM

    Joined:
    Mar 8, 2020
    Posts:
    21
    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

    1. Prevent all attacks from being parried by spamming block

    2. 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.
     
  2. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    369
    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.
     
    Kurt-Dekker likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,371
    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. :)
     
  4. OOVUM

    OOVUM

    Joined:
    Mar 8, 2020
    Posts:
    21
    @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)