- Home /
How to Implement a “Parry” mechanic to a 2D game?
Hello mates! Didn't see any questing about this subject... My name is Eden and I am a student for Game Design and Development. In the latest project of my semester, I am making a 2D game and I want to implement a Parry mechanic. I was wondering if anyone could help me with that type of code? It would mean the world to me if you help me out, or even give general advice on your thought process for this mechanic.
The idea I have for the meantime is: create an animation event method that instantiates a new game object with a collider (let’s say, “enemy parry collider”). create the same one for the player. only if the two new objects collide, get the parry to work. am I doing this right? How can I control the time? Can I also implement a time slow?
Thank you very much in advance, Eden.
can also reach me on my email: edenalon73@gmail.com
Answer by ZozeR · Sep 19, 2020 at 05:51 PM
There are several ways but I think the simplest would be the way you said and it should work without a problem. make sure they are triggers, not colliders, and also make sure they are not children of other objects since their colliders will be part of the parent and destroy the parried collider.
Its more of a unity editor job rather than coding, since all you have to do is create a built-in OnTriggerEnter2D function and add a statement like:
if (collider.tag == "Enemy Damage")
{
if (parry == true)
Parry_Time();
else
Take_Damage();
}
Adding effects is much easier. you can create an object or use an animator for any effect. To slow down time its just Time.timeScale = 0.7f; etc, but if you're using physics you might need to change fixedDeltaTime too.