Children meshes do not update position with a parent rigid body

Hi

I have a problem with creating a dynamic body via code. Everything seems to be working except that the rigid body has some mesh children, but their positions do not get updated…

Is there something wrong here or am missing something? My code used to work just fine in 0.50.

I can also see in scene view(debug) that the rigid body is in another position (where it should be) but the children are reset at 0,0,0.

It seems that the parent transform is not working or something.

Thanks!

1 Like
public static void CreateDynamicBody(Entity entity, float mass, float3 startAngularVelocity, float3 startLinearVelocity, float gravityFactor, float linearDamping, float angularDamping, RigidTransform previousTransform, ref PhysicsCollider colliderComponent, ref EntityCommandBuffer cmdBuffer, EntityManager entityManager)
    {
        PhysicsMass physicsMass = PhysicsMass.CreateDynamic(colliderComponent.MassProperties, mass);
        float3 angularVelocityLocal = math.mul(math.inverse(colliderComponent.MassProperties.MassDistribution.Transform.rot), startAngularVelocity);
        PhysicsVelocity velocityData = new PhysicsVelocity()
        {
            Linear = startLinearVelocity,
            Angular = angularVelocityLocal
        };

        PhysicsDamping damping = new PhysicsDamping()
        {
            Linear = linearDamping,
            Angular = angularDamping
        };

        if (gravityFactor != 1.0f)
        {
            PhysicsGravityFactor gravity = new PhysicsGravityFactor()
            {
                Value = gravityFactor
            };

            if (cmdBuffer.IsCreated)
            {
                cmdBuffer.AddComponent(entity, gravity);
            }
            else
            {
                entityManager.AddComponentData(entity, gravity);
            }
        }


        PhysicsGraphicalSmoothing smoothing = new PhysicsGraphicalSmoothing() { ApplySmoothing = 0, CurrentVelocity = velocityData };
        PhysicsGraphicalInterpolationBuffer interpolationBuffer = new PhysicsGraphicalInterpolationBuffer() { PreviousTransform = previousTransform, PreviousVelocity = new PhysicsVelocity() };

        if (cmdBuffer.IsCreated)
        {
            cmdBuffer.AddComponent<PhysicsGraphicalSmoothing>(entity, smoothing);
            cmdBuffer.AddComponent<PhysicsGraphicalInterpolationBuffer>(entity, interpolationBuffer);
            cmdBuffer.AddComponent(entity, physicsMass);
            cmdBuffer.AddComponent(entity, velocityData);
            cmdBuffer.AddComponent(entity, damping);

        }
        else
        {
            entityManager.AddComponentData<PhysicsGraphicalSmoothing>(entity, smoothing);
            entityManager.AddComponentData<PhysicsGraphicalInterpolationBuffer>(entity, interpolationBuffer);

            entityManager.AddComponentData(entity, physicsMass);
            entityManager.AddComponentData(entity, velocityData);
            entityManager.AddComponentData(entity, damping);
        }
    }

Everything comes from bakers and works fine, but when i run this code to make the parent a rigid body (it also has a simple box collider on it), the children stop getting updated.

What is wrong?

Hello,
I tested this in Unity Physics 1.3.9, and the issue no longer occurs. I have attached a video showing the results of my tests.

In a blank project, I integrated your script and ran it at runtime using a Tag Component to select the bunnies in the scene before adding the Rigidbody at runtime.

I tested two cases:

  • The bunny on the left has multiple colliders, forming a compound Rigidbody.
  • The bunny on the right has a single box collider.

In both cases, without modifying your script, I was able to move the bunny, and all child transforms updated correctly.

Would it be possible for you to confirm if the issue is resolved on your end as well?

I look forward to your response.

Best Regards,
Julian

rigidbodies.zip (793.9 KB)

1 Like

this has been awhile and to be honest i dont remember :smiley: so i guess we can consider it resolved.

2 Likes

Thanks for your quick feedback, I’ll keep an eye on future posts to ensure more timely responses.