AI melee attack completing early, no damage dealt to player

badical

New member
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:
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:
Capture.PNG

AI character Item configuration:
Capture2.PNG

AI character melee weapon configuration:
Capture3.PNG

Thanks!
 
Your setup looks okay - next thing I'd ask is exactly how you're calling the Use ability on the agent? The MeleeAgent script in the demo is a nice example of a basic melee agent script that you may want to take a look at.
 
Thanks for the reply :D

I'm using the Playmaker integration with "Start Stop Use" action:
1622155190985.png

I just tested the MeleeAgent script and disabled my FSM, but the behavior is the same. The AI attacks, but no damage is done because it "completes" the Use action early.


I created a new project that isolates and reproduces this problem. Perhaps it can help identify what I'm doing wrong?
-link deleted-

* You'll need to run Opsive Manager -> Setup -> Project -> Update Buttons and Layers (otherwise it'll throw a ton of errors)
* Player can be controlled by mouse/keyboard and left-click to attack
* Player attacks hit the AI character (there's a sound effect, but also the Health drops in Attribute Manager)
* AI attacks automatically every 5 seconds, but the hits do no damage to the player
* AI attack uses `TryStartAbility` on the `UltimateCharacterLocomotion` component (see AI.cs for the simple attack script)

Your help is very much appreciated. I'm sure it's something silly I'm just not seeing.
 
Last edited by a moderator:
Thanks, I'll take a look at the project - but in the future please send project files via. DMs, not posted on the public forums :)
 
Top