Search Unity

ITriggerJob Sample

Discussion in 'Physics for ECS' started by shotoutgames, Jan 22, 2020.

  1. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
    I am so lost with this so any help much appreciated.

    Code (CSharp):
    1.    struct ListTriggerEventEntitiesJob : ITriggerEventsJob
    2.     {
    3.         [ReadOnly] public ComponentDataFromEntity<PhysicsVelocity> PhysicsVelocityGroup;
    4.         [ReadOnly] public ComponentDataFromEntity<TriggerVolume> VolumeGroup;
    5.  
    6.         [NativeFixedLength(1)] public NativeArray<int> pCounter;
    7.         public NativeArray<TriggerEntities> TriggerEntities;
    8.  
    9.         public void Execute(TriggerEvent triggerEvent)
    10.         {
    11.             Entity entityA = triggerEvent.Entities.EntityA;
    12.             Entity entityB = triggerEvent.Entities.EntityB;
    13.  
    14.             bool isBodyATrigger = VolumeGroup.Exists(entityA);
    15.             bool isBodyBTrigger = VolumeGroup.Exists(entityB);
    16.  
    17.  
    18.             //Ignoring Triggers overlapping other Triggers
    19.             if (isBodyATrigger && isBodyBTrigger)
    20.                 return;
    21.  
    22.             bool isBodyADynamic = PhysicsVelocityGroup.Exists(entityA);
    23.             bool isBodyBDynamic = PhysicsVelocityGroup.Exists(entityB);
    24.  
    25.             // Ignoring overlapping static bodies
    26.             if ((isBodyATrigger && !isBodyBDynamic) ||
    27.                 (isBodyBTrigger && !isBodyADynamic))
    28.                 return;
    29.  
    30.             // Increment the output counter in a thread safe way.
    31.             var count = ++pCounter[0] - 1;
    32.  
    33.             TriggerEntities[count] = new TriggerEntities()
    34.             {
    35.                 VolumeEntity = isBodyATrigger ? entityA : entityB,
    36.                 OverlappingEntity = isBodyATrigger ? entityB : entityA,
    37.             };
    38.         }
    39.     }

    The main thing I am stuck on currently is
    Code (CSharp):
    1.  
    2.             //Ignoring Triggers overlapping other Triggers
    3.             if (isBodyATrigger && isBodyBTrigger)
    4.                 return;
    Why is this ignored?
    I thought ITriggerJob is triggered when two triggers collide so why ignore this when it happens???
     
    destructor465 likes this.
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    991
    ITriggerEvent is raised/trigerred whenever a collider marked as trigger collides with another collider wahterver the type trigger or not.

    In some cases it might make sense to igrone two trigger collider interacting with each other.

    For exemple you make a FPS with "real" projectile (not simple raycast but real physics body and a trigger collider) the projectile travel through the world and cross pass with another trigger colider which purpose is to open a door.
    Do you want the projectile to trigger the opening door animation?
    I think not.
     
    destructor465 and shotoutgames like this.