Self-damage with rocket launcher (UCC3)

zented

Member
Hello, in the demo scene (shooter zone), the character takes no damage when I fire a rocket at my feet.
Is there a way to have self damage?
 
Yes it's possible, We were simply missing a Impact action to deal damage caused by the explosion.

But after testing it out I realised the damage was not scaling with the distance of the explosion, so thank you for bringing this up :)

I added a new option to Simple Damage called "ScaleDamageByImpactStrength" so now it should work as expected.
Here is the code change in Simple Damage (it will be available in the next update).

Code:
[Tooltip("Should the damage be scaled by the impact strength? Use this for explosions!")]
[SerializeField] protected bool m_ScaleDamageByImpactStrength = false;

Code:
/// <summary>
/// Internal method which performs the impact action.
/// </summary>
/// <param name="ctx">Context about the hit.</param>
protected override void OnImpactInternal(ImpactCallbackContext ctx)
{
    var impactData = ctx.ImpactCollisionData;
    
    var damageAmount = m_DamageAmount;
    var damageProcessor = m_DamageProcessor;
    var impactForce = m_ImpactForce;
    var impactforceframes = m_ImpactForceFrames;
    var radius = m_ImpactRadius;
    if (m_UseContextData && ctx.ImpactDamageData != null) {
        damageAmount = ctx.ImpactDamageData.DamageAmount;
        damageProcessor = ctx.ImpactDamageData.DamageProcessor;
        impactForce = ctx.ImpactDamageData.ImpactForce;
        impactforceframes = ctx.ImpactDamageData.ImpactForceFrames;
        radius = ctx.ImpactDamageData.ImpactRadius;
    }
    if (m_ScaleDamageByImpactStrength) {
        damageAmount *= impactData.ImpactStrength;
    }

and here is how I set it up in the inspector
1678103244868.png


Just to keep things clear. In the example above we are doing 40 damage at range 0, not 10. Because "UseContextData" is set to true, the impact action will use the external ImpacDamageData above. If it was false it would use its own data. The reason it works this way is because Impact Actions are used in many contexts and sometimes you want to take external data, sometimes you do not.
So it's up to you if you want to define the damage amount on the ImpactDamageData or in the SimpleDamage Action.

If you want to the impact to damage the player you'll need to make sure the Player layer is set in the LayerMask.
 
Top