I am creating a prototype enemy swordsman, and I'd like to be able to parry his attacks, like the parry system from VR Dungeon Knight.
This is my method of implementation:
- Parent a sword to his hand that has a child cube trigger collider + kinematic rigidbody + a custom script called ParryableWeapon.
- In the animation clip, when he raises his hand before his swing, use an AnimationEvent to tell the ParryableWeapon to start 'listening' for a parry. This is done by checking an internal boolean during OnTriggerEnter of the sword.
- If the ParryableWeapon collides with another ParryableWeapon while listening, the UnityEvent 'OnParried' is invoked.
- After the swing completes, use another AnimationEvent to tell ParryableWeapon to stop 'listening'.
I have a simple model and animation from the Asset store that I'm using to accomplish this. For some reason, the OnParried event is only being fired every 5 or so swings at a stationary test sword.
I played the animation frame by frame, and I found that the enemy swords' position sometimes does not go through the other sword, despite them being on a collision course. In one frame, the enemy sword is to the left of the other, and in the next frame, it is on the other side.
It seems that the interpolated frames between the animation keyframes can only sometimes collide with the other sword. What would be the proper way to remedy this? Adding more keyframes to the animation? Some sort of calculation of the sword's path between the two keyframes?