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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Entity missing physical behavior

Discussion in 'Entity Component System' started by djimon, Jul 31, 2018.

  1. djimon

    djimon

    Joined:
    May 19, 2018
    Posts:
    2
    hey, i'm starting to make a little project using ECS.
    at game start I place some entities.
    Code (CSharp):
    1. var enemyArchetype = entityManager.CreateArchetype(typeof(Enemy), typeof(Rigidbody), typeof(TransformMatrix), typeof(Position), typeof(Rotation));
    2.  
    3. for (int i = 0; i < 5; i++)
    4. {
    5.      var enem = entityManager.CreateEntity(enemyArchetype);
    6.      entityManager.AddSharedComponentData(enem, EnemyLookMI);
    7. }
    8.  
    But after placing them at different positions in a initial script (double checked, that this runs only ones), I would expect them to fall down to the ground (because of the Rigidbody), but they are freezed in the air, where i placed them. Any ideas how the physics like falling, bouncing, etc. would work?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,558
    I am starting with ECS as well, but ECS dosn't have physics as of yet.
    Also, I am not sure, if adding RigidBody is recognizable by entityManager, since this is OOP based component. And you are trying using Hybrid ECS. I may be wrong? It appears you are trying to manipulate Transform via ECS, yet expecting object fall under gravity. May be, that this conflicts?
     
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    ECS works with legacy components, you can inject group with ComponentArray<MonoStuff> where MonoStuff is RB, Collider, etc.
     
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,987
    code?
     
  5. djimon

    djimon

    Joined:
    May 19, 2018
    Posts:
    2
    After some more research and readng I guess experimenting with pure ecs and try to have the Unity build-in physics just work is something not yet available for pure ECS. I may will make a step back and try this dirty hybrid way.
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    Code (CSharp):
    1. public struct AllCitizensGroup
    2.     {
    3.         public ComponentArray<Citizen>             Citizen;
    4.         public ComponentArray<Transform>           Transform;
    5.         public ComponentDataArray<Position>        Position;
    6.         public ComponentArray<NavMeshAgent>        Agents;
    7.         public EntityArray                         Entity;
    8.         public readonly int Length;
    9.         public SubtractiveComponent<LeavedCitizen> Outgoing;
    10.         public SubtractiveComponent<DeadCitizen>   Dead;
    11.         public SubtractiveComponent<TombedCitizen> Tombed;
    12.     }
    13. [Inject] public  AllCitizensGroup                  m_AllCitizens;
    14.  
    15. protected override void OnUpdate()
    16. {
    17. //DO STUFF
    18. if (!m_AllCitizens.Agents[i].isOnNavMesh)
    19.                     {
    20.                         if (NavMesh.SamplePosition(m_AllCitizens.Transform[i].position, out NavMeshHit hit, 10.0f, NavMesh.AllAreas))
    21.                         {
    22.                             m_AllCitizens.Transform[i].position = hit.position;
    23.                         }
    24.                     }
    25. }
    26.