Change Damage Amount

silver91

New member
I got an issue with the damage changing for my player.
C#:
 public class ImpactDamageData : IImpactDamageData
    {
        [Tooltip("The Layer mask to which deal damage.")]
        [SerializeField] protected LayerMask m_LayerMask =
            ~( 1 << LayerManager.IgnoreRaycast
              | 1 << LayerManager.Water
              | 1 << LayerManager.SubCharacter
              | 1 << LayerManager.Overlay
              | 1 << LayerManager.VisualEffect);
        [Tooltip("Processes the damage dealt to a Damage Target.")]
        [SerializeField] protected DamageProcessor m_DamageProcessor;
        [Tooltip("The amount of damage to apply to the hit object.")]
        [SerializeField] public float m_DamageAmount = 10f;
        [Tooltip("The amount of force to apply to the hit object.")]
        [SerializeField] protected float m_ImpactForce = 2;
        [Tooltip("The number of frames to add the impact force to.")]
        [SerializeField] protected int m_ImpactForceFrames = 15;
        [Tooltip("The impact radius.")]
        [SerializeField] protected float m_ImpactRadius;
        [Tooltip("The name of the state to activate upon impact.")]
        [SerializeField] protected string m_ImpactStateName;
        [Tooltip("The number of seconds until the impact state is disabled. A value of -1 will require the state to be disabled manually.")]
        [SerializeField] protected float m_ImpactStateDisableTimer = 10;
        [Tooltip("The Surface Impact defines what effects happen on impact.")]
        [SerializeField] protected SurfaceImpact m_SurfaceImpact;
When i change value here inside impactcolissiondata it works.
What i did is my playerStats script that is attached to player object. When player levels up he gets lets say+ 100 damage
C#:
 public void SetDamageExternally()
        {
            IImpactDamageData impactDamageData = _impactDamageData;

            // Modify the damage amount
            impactDamageData.DamageAmount += 100;
        }
This method is called inside another method when player level UP
C#:
public void AddExp(float expToAdd)
        {
            GlobalValue.SavedCurrentExp += expToAdd;

            if (GlobalValue.SavedCurrentExp > expToNextLevel[GlobalValue.PlayerLevel] && GlobalValue.PlayerLevel < maxLevel)
            {
                
                SetDamageExternally();
                //If player reaches required exp to level up,he gains a level and his HP gets restored fully on "DING"
                GlobalValue.SavedCurrentExp -= expToNextLevel[GlobalValue.PlayerLevel];
            
                GlobalValue.PlayerLevel++;
                StartCoroutine(LevelUpPopUp());
            
              
              GetComponent<GiveLevelToPlayer>().GiveLevelPlayer();

                //player will get 6% more MAX HP each level

                
                var health = _attributemanager.GetAttribute("Health");
                health.MaxValue = Mathf.FloorToInt(health.MaxValue * 1.06f);
                health.Value = health.MaxValue;
                GlobalValue.MaxHp = health.Value;

            }

            if (GlobalValue.PlayerLevel >= maxLevel)
            {
                GlobalValue.SavedCurrentExp = 0;
            }
        }
Reference is inside awake
C#:
private void Awake()
        {
            instance = this;
            //getting component from the Player
           _impactDamageData = new ImpactDamageData();
           }
This is my Rifle prefab and that is what is inside the shootable script
1689157696136.png
This is mine projectile prefab
1689158097575.png
And before you ask yes i tried disabling enabling internal impact
And yes i tried also damage processor like multiplier x100 it didnt work
And yes i tried also edit simple damage inside method like this
C#:
    var inventory = InventorySystemManager.GetInventoryIdentifier(1).Inventory;
    // Get the character Inventory Bridge from the Inventory.
    var characterInventoryBridge = inventory.gameObject.GetCachedComponent<CharacterInventoryBridge>();

    // Get the active character item in slot 0
    var characterItem = characterInventoryBridge.GetActiveCharacterItem(0);
  
    var itemAction = characterItem.GetItemAction(0) as ShootableAction;

    var genericShootableImpactModule = itemAction.ImpactModuleGroup.GetModuleByID(0) as GenericShootableImpactModule;
 
    var simpleDamage = genericShootableImpactModule.ImpactActions.ImpactActions[0] as SimpleDamage;
    // Set the new damage amount.
    simpleDamage.DamageAmount += 100;
Same thing and yes I debug.log in update to see when I level up what is damage amount I check it shows it is 110 but still does 10 damage.
C#:
Debug.Log(_impactDamageData.DamageAmount);
Next picture is inside game when i press Play Under Items
1689158585754.png
And yes i tried those with overrride and modify and damage is never 15. I tried change it there also but no effect.
That is mine pickup prefab
1689158744272.png

Let me know if you have more questions. Thanks a lot!
 
C#:
  public float DamageAmount  {
            get { return PlayerPrefs.GetFloat("PlayerDamage",50); }
            set
            {
                PlayerPrefs.SetFloat("PlayerDamage", value);
            }
        }

We have to change this in ImpactCollisionData SCRIPT LINE 521 Damage Amount. I don't know why it works but it works. I guess it had to be saved in order for damage to change. Something was returning to default 10 dmg all the time. Now my SetDamageExternally(); method works. After 3 days I finally solved it. I hope others can use this for future reference. If they ever decide to have an upgrade system , talent tree, or something.
 
Using PlayerPrefs really isn't a good idea. It does not scale at all.

From the code you shared I still do not understand how you are using "_impactDamageData" to set the impact damage data on your weapon.
One thing I believe you might have misunderstood is that the ContextData is reset on each hit. That means you cannot set the damage amount within the context from an externally script once, as it will simply be reset when the next hit happens.

On top of that you are binding the DamageAmount property to the DamageAmount on your weapon item attribute:
1689234114051.png

That's probably the reason why it's always 10 even when you untick the useContextData. Because it grabs the value from your Item.


Long Story short, I don't think your approach is a good one.
But clearly that shows that I haven't made things clear in the demo or the documentation on how to use a damage processor or a custom ImpactAction.

Here in the next update I will be adding these orbs that can change the damage at runtime within the Integration demo scene:
1689241250475.png

I'm attaching below the "IntegrationDemoDamageProcessor" script that is well commented to explain how to make a damage processor that can compute damage using both data on the Character and on the Item.
This is how I've set it up
1689242499494.png

1689242364499.png

Of course this is just an Example for the demo, but
I'm hoping this will guide you in the right direction.
 

Attachments

I see. I notice what my code did. It is not changing the gun damage actually. Now when i control this value it is for character damage like base damage we can say. Any gun I equip it will inherit that damage from me that I did with that code. So no more unique damage to the guns.
I did added more code so i can call it in abilities also like giving my burst ability more damage for some time. And Reset back damage after its done. And each level character gets 7 % increase in damage.
1689246340521.png
I agreed it is not good aproach for sure. Unique item lose purpose because all damaged is based on character.
I will try your aproach now and see how it goes with it.
As i said on discord : It would be good to have editing damage overall for many games i mean if you gonna have talent tree or you just using it for melee combat. Upgrading stats damage etc. I am looking for other stats also such as fire rate , range of the gun which i can edit. If all this can be edited would be great and it could extend making games more unique and engaging. What i can say peoples love numbers....
 
Back
Top