Impact State Transitions

Things seem to work but when the enemy swings the sword, the player doesn’t take the damage occasionally. I checked the timining of collider on the sword being enabled and concluded this doesn’t have to do with collider.

What values do I need to fine-tune to ensure every swing correctly registers?

P.S. I believe I wrote my code exactly like the lecture.

Hey @Hyunsang_Joo can you doube check your HEALTH value? if it’s 0 you will not see the imapct animation. Set it to a low value to test. I thought i had the same issue but it turned out … i just didnt have any Health left

@Nina can you please Tag the post corectly ?

@mihaivladan, unfortunately, I do not know the correct tag. I’m a/the teaching assistent in the Unity 2D and Unity 3D courses only (but not in the Unity RPG courses). Maybe @Marc_Carlyon can help with the missing tags?

For some reason this tag was not created.
It was 10_ai_utp.

If its not health then it could be something else.

If i remember correctly we set the colliders using events on the animations so that we turn the collider one at a set point in the animation and off again at a later point.
I would check the sword collider first of all and then go into the attack animation and events on the animations that we set for the attacks.

You may need to pause the game play and see if there is anything else that could cause it to miss.

Let me know how you get on

1 Like

That was one of the problems I faced, but set the health to 1,000 for the sake of testing. The issue remains unresolved.

Thanks, that’s what exactly I did.
Above all, after increasing the sizes of the sword and character colliders, things get better.
(I adjusted the animation events too)
Not the hit registers 90% of the time.
Still, the hit doesn’t register even if the sword slashes through the character body.
Do I need to adjust colliders more? Because I don’t think there’s nothing wrong with the code.
(If there is, working 90% of the time doesn’t make sense)

At this point i would go to the course resources and lick the lecture project changes link.
At that page there is a browse files button and then a download icon.
This way you can download our project and compare the colliders side by side but also anything that might be an issue which is far easier than comparing it from the video.
I mention this as it could still be the colliders but i may not be able to respond again until monday so this at least gives you a thread to pull on in the meantime and you may find a solution.

I have tested this in my project and it does not seem to be an issue.
I am assuming you are using the same models/animation but even if not we seem to be on the right track for a resolution.

Hey @Hyunsang_Joo please do the following

  1. Create a new test scene with just the player and an enemy you have. Once that’s done right-click on it > Select Dependencies
  2. Once you have that list, right-click again and create a new unity package.
  3. Upload that package on Dropbox/Google Drive/ One Drive / etc and post the link here so I can download it and take a look.

I found that I needed to exaggerate my colliders quite a bit. I also needed to bring the EnableWeapon/DisableWeapon events further out from the expected impact zone. If you Enable the collider while it is already intersecting with the opponent’s CharacterController collider, the OnTriggerEnter() doesn’t seem to fire reliably.

I had created two enemies, the Knight which is about the same height as the Paladin and a brute that is about 1.25x the height. The brute didn’t require any tweaking, but the knight was making around an 80% hit rate. I found that a slight variation in terrain height between the payer and enemy was just enough to sometimes cause the collider to miss. Increasing the collider radius to .3 upped the hit rate to over 90% and changing the attack range from 1.5 to 1.4 brought it pretty close to 100%.

I did tweak the animation event a little, but found when a second enemy was thrown into the mix it created some funny conditions where they would strike each other during winding up to hit the player, so ended up increasing the length the collider is on only 3 frames or so for each of the animations.