Opsive UCC + PUN Damage Problem

Hello, i have a question regarding the Damage system in opsive..
i want to make a headshot system, so i put a hitcollider in my player head and attach the hitcollider in player character health component on my character and set the multiplier value to 0, the goal is to catch if the player was hit in the head (compare by tag) and the damage is 0 i will apply damage to the character equal to its health value so the character will automatically dead..
but i encounter a strange behavior where its run very nice when i shoot the character from the short distance, but it will not work from long distance..
below i attach the setup, code, and video.

Code:
using Opsive.Shared.Events;
using Opsive.UltimateCharacterController.Traits;
using Opsive.UltimateCharacterController.Traits.Damage;
using UnityEngine;

public class HeadshootHandler : MonoBehaviour
{
    private CharacterHealth _playerHealth;

    public void Awake()
    {
        EventHandler.RegisterEvent<DamageData>(gameObject, "OnHealthDamageWithData", OnDamageWithData);

        _playerHealth = this.GetComponent<CharacterHealth>();
    }

    //detect when the player is attacked
    private void OnDamageWithData(DamageData damageData)
    {
        if (damageData.HitCollider == null)
            return;

        if (damageData.HitCollider.CompareTag("HeadCollider"))
        {
            DamageData headshootDamageData = new DamageData();

            headshootDamageData.Amount = _playerHealth.Value;
            headshootDamageData.Direction = Vector3.zero; //TIO: not sure what to put here
            headshootDamageData.Position = transform.position; //TIO: not sure what to put here
            headshootDamageData.Radius = 1; //TIO: not sure what to put here
            headshootDamageData.Frames = 1; //TIO: not sure what to put here
            headshootDamageData.ForceMagnitude = 0; //TIO: not sure what to put here
            headshootDamageData.HitCollider = damageData.HitCollider; //TIO: this is from the parameter
            headshootDamageData.DamageOriginator = damageData.DamageOriginator;
            headshootDamageData.DamageTarget = GetComponent<CharacterHealth>();
            //TIO: flag to tell that this is a headshot
            headshootDamageData.UserData = "hs";

            _playerHealth.Damage(headshootDamageData);

            if (_playerHealth.IsAlive())
                _playerHealth.ImmediateDeath();
        }
        else
        {
            Debug.Log("head collider not detected: " + damageData.HitCollider);
        }
    }

    public void OnDestroy()
    {
        EventHandler.UnregisterEvent<DamageData>(gameObject, "OnHealthDamageWithData", OnDamageWithData);
    }
}

WhatsApp Image 2023-07-05 at 14.01.06.jpeg


 
If you place a breakpoint within the OnDamageWithData method can you compare the variables between a short hit and a long hit? This should start to point in the right direction for what is wrong.
 
Hello Justin,
i have tried to put a breakpoint to the OnDamageWithData method, and the hitCollider for a short hit is head collider, for long is CapsuleCollider, i think the mechanism in the OnDamageWithData method is okay, but is there something wrong within the raycast?
 
In that case you could place a breakpoint within the module that is doing the raycast to determine why it's getting a different result. By default HitscanShooter.HitscanFire is used for hitscan weapons.
 
Top