Player Character not taking damage from the front in melee

AJ_Dubya

New member
Hi there,

As the title suggests, I am having an issue where the player character does not receive damage from the front while holding a melee weapon and being attacked by a melee weapon at the same time. Neither the Aim or Block abilities are active, and the Shield component on the weapon is set to 'Require Aim', yet still no damage is being taken, however if I turn the Player to the side or have my back facing the attacker then he receives damage. Also, the Block ability Start & Stop Types are set to Manual. This issue does not affect AI characters, just the Player, and only when the weapon has the Shield component. I notice this happening in the Demo scenes as well. There are no console errors appearing.
Any ideas what might be the problem?

Edit: If it helps, I have the First Person Controller, Ultimate Inventory System, and Behaviour Designer

Thanks!
 

Andrew

Moderator
Staff member
Hm, yes I can confirm this happens in the demo scene too.

@Justin If I'm not mistaken this is happening because the enemy's melee weapon collides with the character's Shield object first (even if it's not Aimed), which doesn't have the Health component, so it just applies the force and not the damage? I.e. MeleeWeapon:803.
 

Justin

Administrator
Staff member
That's likely correct. When the enemy hits the shield the RequireAim toggle is compared to determine if it should do any damage. If RequireAim is deselected then it will not do any damage.
 

AJ_Dubya

New member
That's likely correct. When the enemy hits the shield the RequireAim toggle is compared to determine if it should do any damage. If RequireAim is deselected then it will not do any damage.

Thanks for the replies! The issue is that the RequireAim toggle is selected yet still no damage is being received by the character even when not aiming. Is there something else I need to add to the weapon? Also, it only seems to affect the Player character, not AI characters with the same weapon.

Currently it has these components:
  • Transform
  • Item (script)
  • First Person Perspective Item (script)
  • Third Person Perspective Item (script)
  • Melee Weapon (script)
  • First Person Melee Weapon Properties (script)
  • Third Person Melee Weapon Properties (script)
  • Shield (script)
 
Last edited:

Justin

Administrator
Staff member
Just letting you know that I plan on taking a closer look at this and will let you know after I do.
 

Justin

Administrator
Staff member
I am looking closer into this and am unable to reproduce it within the demo scene. I am in the melee room and enabled Required Aim on the Agent Nolan's shield. I then disabled the aim ability so the agent is not aiming and added the Health component.

When I attack the shield the agent's health decreases. Do I need to do anything else to reproduce the issue? With that said, when I debugged this I noticed that depending on the settings you are using for the melee weapon there's a chance that the melee weapon will not continue to hit other objects. Within MeleeWeapon.HitCollider you should change:

Code:
                damageAmount = shieldDamageAmount;
                m_SolidObjectHit = m_ApplyRecoil;
to:
Code:
                m_SolidObjectHit = m_ApplyRecoil && damageAmount != shieldDamageAmount;
                damageAmount = shieldDamageAmount;
 

AJ_Dubya

New member
I am looking closer into this and am unable to reproduce it within the demo scene. I am in the melee room and enabled Required Aim on the Agent Nolan's shield. I then disabled the aim ability so the agent is not aiming and added the Health component.

When I attack the shield the agent's health decreases. Do I need to do anything else to reproduce the issue? With that said, when I debugged this I noticed that depending on the settings you are using for the melee weapon there's a chance that the melee weapon will not continue to hit other objects. Within MeleeWeapon.HitCollider you should change:

Code:
                damageAmount = shieldDamageAmount;
                m_SolidObjectHit = m_ApplyRecoil;
to:
Code:
                m_SolidObjectHit = m_ApplyRecoil && damageAmount != shieldDamageAmount;
                damageAmount = shieldDamageAmount;
Thanks for your reply Justin. There may be a misunderstanding - the issue only seems to affect the player character, not the AI Agent Nolan. If you turn your back to the AI character (Agent Nolan) and he attacks, you will receive damage. But when facing him front on, even when not blocking, no damage is received by the player character (Nolan).

I hope that makes sense and I haven't misunderstood what you already tried.
 

Justin

Administrator
Staff member
Did you make the change that I described? I just tested it with Nolan and when Require Aim is enabled the damage does go through to the character. I also ensure the AI agent hit the shield. From the shield/melee weapon/health perspective it doesn't matter if it's an AI agent or not.
 

AJ_Dubya

New member
Did you make the change that I described? I just tested it with Nolan and when Require Aim is enabled the damage does go through to the character. I also ensure the AI agent hit the shield. From the shield/melee weapon/health perspective it doesn't matter if it's an AI agent or not.
Thanks for your reply - I did edit the script as you described. I also just tried creating a completely new project with only the First Person Character Controller asset installed, made no other changes, and still had the same issue. I then edited the script in the new project as you described and still no damage is being received from the front. Not sure what is going on!

Other things I have noticed
- this only occurs with the Katana and Sword, but not the Knife (which has no Shield component). So appears to be related to the Shield component
- while using a melee weapon, in the Animator it shows Nolan using the Melee Aim Idle even while not using Aim; in Nolan's 'Ultimate Character Locomotion' component, if I turn off 'Activate in First Person' under the Aim item ability it resolves this and he is uses Idle until Aim is activated, however still receives no damage from the front when just in Idle while holding the Sword or Katana
 

Andrew

Moderator
Staff member
I'm also unable to reproduce this... what version of UCC are you on?

Also, the Aim states in the animator are not exactly related to the Aim/Zoom ability so that's to be expected.
 

AJ_Dubya

New member
I'm also unable to reproduce this... what version of UCC are you on?

Also, the Aim states in the animator are not exactly related to the Aim/Zoom ability so that's to be expected.

This is using First Person Controller version 2.2.8 on the Unity store. And using Unity version 2019.4.17f1
 

Justin

Administrator
Staff member
If you place a breakpoint within Shield.Damage are you able to determine why the health isn't being affected? You can place a breakpoint on this line:

Code:
            if (!m_Aiming && m_RequireAim) {
                return amount;
            }

And this line should eventually be called within Health.OnDamage:
Code:
            if (m_HealthAttribute != null && m_HealthAttribute.Value > m_HealthAttribute.MinValue) {
                m_HealthAttribute.Value -= Mathf.Min(amount, m_HealthAttribute.Value - m_HealthAttribute.MinValue);
            }
 
Top