2
\$\begingroup\$

I have a moving platform that is a kinematic body, moving by a script, which is working as expected.

I tried to parent it to another kinematic body, and make the child also function as a moving platform (the script only moves the parent), but it seems that the friction is ignored for the child object, and the carried object slips behind it and falls down when the child platform moves. The child platform is the same physical material as the parent.

Is there any way i can make the child's friction work too, while having the script only move the parent?

This is important, because in my real application the child moves and rotates inside a couple nested levels of transformations (basically the fork teeth of a fork truck).

here is a simple abstraction of my question:

https://youtu.be/U854IcS96-Y

Thanks!

\$\endgroup\$
2
\$\begingroup\$

Parenting physics bodies can often be fraught. What I'd recommend doing instead is:

For each child that needs to move in the parent space of another body, create an empty "marker" object, and apply the animation/movement scripts to that marker.

In your kinematic rigidbodies that need to follow these markers, add a script like this:

public Transform followMarker;
Rigidbody _body;

void Start() {
    // Eject from our place in the child hierarchy,
    // so the parent's transform no longer affects us.
    transform.parent = null;

    _body = GetComponent<Rigidbody>();
}

void FixedUpdate() {
    // Move (in world space) to match the position & orientation
    // of our marker object under its parent(s).
    _body.MovePosition(followMarker.position);
    _body.MoveRotation(followMarker.rotation);
}

Now you can get the best of both worlds: Your markers can use child hierarchies to perform complex movements relative to their parent bodies, and your physics platforms can match them without interference from the parenting structure.

\$\endgroup\$
  • \$\begingroup\$ that does it! the child is still slightly loose (skipped frames?) but otherwise it is working beautifully.many thanks. \$\endgroup\$ – oded wolff Nov 4 '17 at 11:47
  • \$\begingroup\$ This can occur due to differences in update order. You can add an extra fixup move in Update or LateUpdate too, to snap it into alignment before a frame is rendered. Or if you're using interpolation/extrapolation, you might need to use velocities so there's a clue about how to offset its rendered version between physics steps. \$\endgroup\$ – DMGregory Nov 4 '17 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.