Listening to hit events
Receive hit geometry, bullet properties, shot IDs and shooter attribution.
Objects need colliders on layers included by Ray Mask. Add this separate component to the tutorial scene to print hit information:
using IE.RSB;
using UnityEngine;
public sealed class TutorialHits : MonoBehaviour
{
private void OnEnable()
{
SniperAndBallisticsSystem.EAnyHit += OnHit;
}
private void OnDisable()
{
SniperAndBallisticsSystem.EAnyHit -= OnHit;
}
private void OnHit(BulletPoint point)
{
Debug.Log($"Shot {point.m_shotId}: {point.m_hitType} at {point.m_endPoint}, " +
$"energy {point.m_kineticEnergy} J", point.m_hitCollider);
}
}| Event | When it is sent |
|---|---|
ENormalHit | A hit that neither penetrates nor ricochets. |
EPenetrationInHit | Entry into a penetrable surface. |
EPenetrationOutHit | Exit from the penetrated surface with sufficient remaining energy. |
ERicochetHit | A bounce from a surface. |
EAnyHit | Every one of the above. |
Every hit callback takes one BulletPoint. Its m_endPoint is the impact position, m_hitNormal is the normal, m_hitCollider identifies the exact collider and m_hitRigidbody is its attached body, if any. m_hitTransform retains the older RaycastHit.transform behavior and may identify a rigidbody parent. See BulletPoint for all fields.
These events are static and shared by all shots. Filter by target, m_properties, m_shooter or m_shotId, and unsubscribe when disabled. Per-shot calls report their supplied Shooter; legacy calls report null. Every accepted firing call has its own ID, retained across penetration, ricochet and bullet-time replay.
One bullet can produce multiple events; EAnyHit does not mean one damage application per shot. Read optional base damage from point.m_properties.DamageProfile, checking for null. See Ammunition damage for a complete target listener and entry/exit handling.
Use src/Hits/HitListenerApplyForce.cs as an example for applying impulses to hit Rigidbodies. Continue with Spawning particles for visual responses.