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:

  1. Parent a sword to his hand that has a child cube trigger collider + kinematic rigidbody + a custom script called ParryableWeapon.
  2. 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.
  3. If the ParryableWeapon collides with another ParryableWeapon while listening, the UnityEvent 'OnParried' is invoked.
  4. 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.

Frame 1 Frame 2

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?

My issue was that I expected OnTriggerEnter() to perform the same continuous collision detection that OnColliderEnter() would. That is apparently not the case. Instead of the collision detection implementation I described, I did a CapsuleCast during the parryable weapon frames, setting the ends of the capsule at the sword's tip and guard and against a custom collision layer.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.