Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

ITriggerJob Sample

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

  1. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    267
    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. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    869
    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.