Defence setting has a strange behavior for me

Hello.
For me, when I create an armor for torso of 5 additive modificator, my hit points given by enemy dramatically collapse.
I barely unbreakable.
here is my log during the fight:
image.

The enemies who have no defence correctly lost there hit point but not me.
I precise I have this kind of result with or without armor modification.

with armor:
image

here is my armor resource :

For information Percentage modifier works correctly, by adding my player 20% more life.

here is the enemies progression:
image

so 5/8 = 0.625 as in the course.

And my code in fighter script:

private void Hit()

        {

            //Si on sort du combat avant la frame qui déclenche l'event hit, alors on ne lit pas la suite du code. Evite le message d'erreur NullReferenceException

            if(target == null) {return;}

            float damage = GetComponent<BaseStats>().GetStat(Stat.Damage);

            BaseStats targetBaseStats = target.GetComponent<BaseStats>();

            if(targetBaseStats != null)

            {            

                float defence = targetBaseStats.GetStat(Stat.Defence);

                damage /= 1 + defence / damage;

            }

            if(currentWeapon.value != null)

            {

                currentWeapon.value.OnHit();

            }

           

            if(currentWeaponConfig.HasProjectile())//Si l'arme actuelle est une arme à munitions

            {

                currentWeaponConfig.LaunchProjectile(rightHandTransform, leftHandTransform, target, gameObject, damage);

            }else{

                target.TakeDamage(gameObject, damage);//target étant relié directement au script Healt, on lance la méthode TakeDamage à chaque event hit.

            }//gameObject represente la personne qui inflige les dégats.

               

        }

Any Idea?
Thanks
François

With the information provided, 8 (the initial damage) divided by the sum of 1 + 5/8 is 4.92

That may not be your true defense, however. In order to get a defense stat at all, the stat must exist in the Progression for that class, and it’s likely not zero. Can you show the value of the stat in the table?

Just to help with seeing what’s going on behind the scenes in Hit(), let’s also add this debug:

if(targetBaseStats!=null)
{
    float defence = targetBaseStats.GetStat(Stat.Defense);
    Debug.Log($"{name} hit {target.name} with {damage} attack.  Target's defense = {defence}");
    Debug.Log($"{damage} /= 1 + {defence}/{damage} = {damage / 1 + defense / damage}");
    damage /= 1 + defence / damage;
}

Well…
How to say…
:slight_smile:
It’s the problem when you follow a course and don’t reach the end of the actual lesson in one time…
I had created a defence table and probablyleave unity to make something else…
Here is my table lol…
image

It was a duplication of the Health table lol :smiley:

and your log event help me to find this, thank you Brian.
image

It works better with a normal table .
I had another strange behavior, my enemies have 1000 hit point for level 1 each…
In my table it was 60 points…
Looking the enemies prefab in the scene, I notice that there Base Stat script was set in character class …
Player ! :slight_smile:
So normal, 1000 hit points…
Pffff
Sorry for the trouble.

I 've noticed something else working wrong.
When I test combat against bowman, the damage is only the table’s basic damage.
It doesn’t look to take care about projectile damage.
My debug log display i’m hitting by 15 points the projectile value but in fact I’m only hit by 8 points, the basic damage of the table.

Any Idea?
Maybe it’s solve later in another lesson?
Thanks.
François

Sam’s design assumed that enemies would never have any special modifiers… so he left the weapon modifiers out of the design by leaving enemies not checking for IHasModifierProviders.

The trick is to treat the bad guys just like we treat our players.

  • Put a StatsEquipment on the enemy
  • Check the “Use Modifiers” button on the BaseStats for the enemy.
  • Add the script below to the enemy
using GameDevTV.Inventories;
using UnityEngine;

namespace RPG.Inventories
{
    public class NPCEquipmentGiver : MonoBehaviour
    {
        [SerializeField] private EquipableItem[] itemsToEquip = [];

        private void Start()
        {
            if(TryGetComponent(out Equipment equipment))
            {
                foreach (EquipableItem item in itemsToEquip)
                {
                    if (item == null)
                    {
                        continue;
                    }

                    equipment.AddItem(item.GetAllowedEquipLocation(), item);
                }
            }
        }
    }
}

Then you can add the weapon to this location and it will ensure that the item is properly equipped using the Inventory System and that any modifiers on the weapon will be applied.

You can also add armor items here which would be modifiers for the enemy’s defense.

So nice :slight_smile:
Thank you Brian.
I’ll test this.
HAve a good day.
François

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms