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 March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question How to create Joints in 0.50.0

Discussion in 'Physics for ECS' started by Occuros, Mar 23, 2022.

  1. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    232
    The ECS samples for physics haven't been updated just yet, and the documentation is a little sparse when it comes to joints.

    What is currently needed to create a joint (Fixed Joint for example) between two entities?

    I tried to add the component returned by:
    PhysicsJoint.CreateFixed
    but that seems to have no effect.

    A simple example to create a fixed joint would be appreciated.
     
  2. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    232
    I tried the following:


    Code (CSharp):
    1.      
    2. var joint = PhysicsJoint.CreateFixed(new BodyFrame(), new BodyFrame());
    3. var jointEntity = ecb.CreateEntity();
    4. ecb.SetName(jointEntity, $"FixedJoint {e.EntityA.Index} - {e.EntityB.Index}");
    5. ecb.AddComponent(jointEntity, new PhysicsConstrainedBodyPair(e.EntityA, e.EntityB, false));
    6. ecb.AddComponent(jointEntity, joint);
    7.  
    But it seems that these constraints have no effect (although the entity is created.

    I probably am missing something small to make it work properly.
     
  3. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Code (CSharp):
    1. EntityManager.AddSharedComponentData(jointEntity, new PhysicsWorldIndex(0));
    2. var bodyPair = new PhysicsConstainedBodyPair(bodyA, bodyB, collisionEnabled);
    3. EntityManager.SetComponentData(jointEntity, bodyPair);
    4. var joint = PhysicsJoint.CreateFixed(
    5.                     new RigidTransform(OrientationLocal, PositionLocal),
    6.                     new RigidTransform(OrientationInConnectedEntity, PositionInConnectedEntity)
    7.                 );
    8. EntityManager.SetComponentData(jointEntity, joint);
     
    DevViktoria and Occuros like this.
  4. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    232
    Indeed forgot to set the `PhysicsWorldIndex`, Thank you!
     
  5. JosepMariaPujol

    JosepMariaPujol

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    77
    NT_Ninetails likes this.