bevy_xpbd icon indicating copy to clipboard operation
bevy_xpbd copied to clipboard

Document position/transform hierarchy behaviour

Open cBournhonesque opened this issue 1 week ago • 0 comments
trafficstars

I was having an issue where Position/Rotation are not updated/replicated correctly for child entities.

After some experiments/searching, I realized that:

  • if you spawn a parent RigidBody, Position/Rotation will be added to it

  • you can handle more complex shapes by spawning child Colliders with Transform.

  • the Position/Rotation of these child colliders is manually set from the Transform in https://github.com/avianphysics/avian/blob/main/src/collision/collider/collider_transform/plugin.rs#L67

However it seems like i'm missing something.

    let server_parent = stepper
        .server_app
        .world_mut()
        .spawn((
            Replicate::to_clients(NetworkTarget::All),
            RigidBody::Kinematic,
            Position::from_xy(1.0, 1.0),
            Transform::from_xyz(1.0, 1.0, 0.0),
            LinearVelocity(Vector::new(100.0, 0.0)),
            Collider::circle(1.0),
            Rotation::default(),
        ))
        .id();
    let server_child = stepper
        .server_app
        .world_mut()
        .spawn((
            ChildOf(server_parent),
            Position::from_xy(3.0, 3.0),
            Transform::from_xyz(2.0, 2.0, 0.0),
            Collider::circle(1.0),
            Rotation::default(),
        ))
        .id();

If I do this, and call app.update() once, then the child's position is still Position::from_xy(3.0, ..), instead of Position::from_xy(4.0, ..) (which would be expected because the parent's position was updated, and then that change is propagated from parent to child).

Why does this happen? Am I not supposed to manually add Position/Rotation to child Colliders of a RigidBody? It feels like this case should be handled by https://github.com/avianphysics/avian/blob/main/src/collision/collider/collider_transform/plugin.rs#L67

cBournhonesque avatar Nov 09 '25 23:11 cBournhonesque