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.

Joints in Unity Tiny

Discussion in 'Physics for ECS' started by leon-sunday, May 5, 2021.

  1. leon-sunday


    May 19, 2020
    Hi, I have been trying to add constrains to a Physics Body and I also want to create a Hinge Joint. I found some samples in the "EntityComponentSystemSamples" but they are using Unity.Physics.Hybrid which requires Linq and that seems to be missing in Unity Tiny.

    So, I tried to create a "Pure" ECS equivalent but I have failed maybe someone can help me with this. I attached the Component and a system that creates the Joint but as I said it doesn't work.

    Attached Files:

  2. steveeHavok


    Mar 19, 2019
    You are creating the
    component that defines the joint reference frames and constraints but you also need to create the
    component in order to specify which body entities are to be joined. As a reference, see the Scene Creation utilities functions that the demos use when creating Joints in code.

    Code (CSharp):
    1.     public Entity CreateJoint(PhysicsJoint joint, Entity entityA, Entity entityB, bool enableCollision = false)
    2.     {
    3.         var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    4.         ComponentType[] componentTypes =
    5.         {
    6.             typeof(PhysicsConstrainedBodyPair),
    7.             typeof(PhysicsJoint)
    8.         };
    9.         Entity jointEntity = entityManager.CreateEntity(componentTypes);
    11.         entityManager.SetComponentData(jointEntity, new PhysicsConstrainedBodyPair(entityA, entityB, enableCollision));
    12.         entityManager.SetComponentData(jointEntity, joint);
    14.         return jointEntity;
    15.     }
    Naotagrey likes this.