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.

PhysicsBody & PhysicsShape Trigger Grid

Discussion in 'Physics for ECS' started by lndcobra, Nov 10, 2020.

  1. lndcobra

    lndcobra

    Joined:
    Jan 28, 2020
    Posts:
    21
    Hey, just thought I would post this in case it helps anyone else as I spent over 2 hours trying to figure out why one of my triggers wasn't firing (turned out you need a non Static PhysicsBody at least on one of the entities!)

    upload_2020-11-10_0-40-15.png

    These are the combinations of PhysicsBody.CollisionResponse and PhysicsShape.MotionType that trigger a Physics Trigger in DOTS/ECS.

    This was created on

    - Unity - 2020.1.11f1
    - Unity Physics - Version 0.5.1-preview.2 - October 29, 2020
    - Entities - Version 0.16.0-preview.21 - October 29, 2020

    Code Used To Test:

    Code (CSharp):
    1. public class PhysicsCollisionTest : SystemBase
    2. {
    3.     protected override void OnCreate()
    4.     {
    5.         _physicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
    6.         _stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
    7.         _ecbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
    8.     }
    9.  
    10.     protected override void OnUpdate()
    11.     {
    12.         // Debug.Log("PhysicsCollisionTest OnUpdate");
    13.         // var ecb = _ecbSystem.CreateCommandBuffer().AsParallelWriter();
    14.        
    15.         Dependency = new TriggerJob
    16.         {
    17.             Version = 1,
    18.             Name = GetComponentDataFromEntity<NameComponent>(),
    19.             // Ecb = ecb,
    20.         }.Schedule(_stepPhysicsWorld.Simulation, ref _physicsWorld.PhysicsWorld, Dependency);
    21.        
    22.         // _ecbSystem.AddJobHandleForProducer(Dependency);
    23.     }
    24.     private BuildPhysicsWorld _physicsWorld;
    25.  
    26.     private StepPhysicsWorld _stepPhysicsWorld;
    27.     private EndSimulationEntityCommandBufferSystem _ecbSystem;
    28.  
    29. }
    30.  
    31. [BurstCompile]
    32. public struct TriggerJob : ITriggerEventsJob
    33. {
    34.     public int Version;
    35.  
    36.     [ReadOnly] public ComponentDataFromEntity<NameComponent> Name;
    37.  
    38.     // public EntityCommandBuffer.ParallelWriter Ecb;
    39.     public void Execute(TriggerEvent e)
    40.     {
    41.         var aName = Name[e.EntityA].Name;
    42.         var bName = Name[e.EntityB].Name;
    43.         Debug.Log($"Trigger Fires: EntityA[{aName}]={e.EntityA.Index} with EntityB[{bName}]={e.EntityB.Index} JobVersion={Version}");
    44.     }
    45. }
     

    Attached Files:

    varnon likes this.
  2. lndcobra

    lndcobra

    Joined:
    Jan 28, 2020
    Posts:
    21
    Found my issue of why a PhysicsBody was screwing my movement/location.
    I have a fireball prefab, and inside there a sphere which initially had collider, physics shape. As I instantiate the prefab and move the prefab all was working, but when I added a PhysicsBody to the Sphere, I guess it controlled its own absolute "World Position" and no longer moved along with the prefab. So although I was moving the Prefab, the child sphere PhysicsBody was not moving! Wished there was a list of these gotchas,

    @Havok/Unity do you know if there is anyway to contribute to the official Docs, things like this should be highlighted and documented, will save hours of learning/finding stuff out!
     
    steveeHavok likes this.