I followed the Melee Weapon Setup tutorial to create a body item on the player, colliders in the hands, etc. This works when I put an AI character in the scene and attack it. The health attribute decreases, sound effects fire, death occurs, and respawn happens. Great!
The problem is when the AI character attacks the player. I've scripted the AI to repeat the Use ability to attack every 5 seconds. The attack happens, animations fire, etc- but no damage is dealt to the player.
After debugging, I can see that the MeleeWeapon script exits early because of this line:
This `return` is also happens when the player attacks, except this is called many times across the frames for the player and only a single time for the AI.
Further debugging leads me to this block of code being called from the Use.cs script later during the frame:
Which appears the "complete" the attack on the first frame, preventing it from being evaluated again. Meaning that `m_CanHitDelay` never has a chance to trigger the hitbox collisions. This explains why the attacks are never dealing damage, but I don't know why this is happening.
I believe there's something different about the lifecycle between my AI and the Player, but I can't figure it out. The difference that comes to mind is how the attacks are started: for the Player I'm using Button Down/Button Up, but for the AI it's Manual. I'm not sure why this would change the behavior, though- perhaps just a red herring.
Any suggestions?
AI character Item Ability configuration:
AI character Item configuration:
AI character melee weapon configuration:
Thanks!
The problem is when the AI character attacks the player. I've scripted the AI to repeat the Use ability to attack every 5 seconds. The attack happens, animations fire, etc- but no damage is dealt to the player.
After debugging, I can see that the MeleeWeapon script exits early because of this line:
C#:
// The item can't hit anything until after the delay.
if (m_AttackTime + m_CanHitDelay > Time.time) {
return;
}
This `return` is also happens when the player attacks, except this is called many times across the frames for the player and only a single time for the AI.
Further debugging leads me to this block of code being called from the Use.cs script later during the frame:
C#:
// The item needs to be used before the complete event can be called.
if (!m_UsableItems[i].IsItemUsePending()) {
ScheduleCompleteEvent(i, true);
}
Which appears the "complete" the attack on the first frame, preventing it from being evaluated again. Meaning that `m_CanHitDelay` never has a chance to trigger the hitbox collisions. This explains why the attacks are never dealing damage, but I don't know why this is happening.
I believe there's something different about the lifecycle between my AI and the Player, but I can't figure it out. The difference that comes to mind is how the attacks are started: for the Player I'm using Button Down/Button Up, but for the AI it's Manual. I'm not sure why this would change the behavior, though- perhaps just a red herring.
Any suggestions?
AI character Item Ability configuration:
AI character Item configuration:
AI character melee weapon configuration:
Thanks!