Apologies for a dumb question: I’m sure I’ve solved this problem before with characters on moving platforms, but nonetheless I’m getting behaviour that’s confusing me now.
I have two cubes stacked on top of each other, each with a box collider and rigidbody.
The upper cube is the child of the lower cube. Gravity on both rigidbodies is disabled.
In editor and play mode, moving the parent cube by dragging the transform widget moves the child cube (it inherits the transformation).
However, when I run the following simple test code on the parent (moving it with movePosition), the child cube remains motionless, failing to inherit the transformation of the parent.
private Rigidbody rb;
public float percent = 0.0f;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
percent += Time.deltaTime;
rb.MovePosition(Vector3.MoveTowards(Vector3.up * 2 + Vector3.left * 4, Vector3.up * 2 + Vector3.right * 4, percent));
}
As I say, I’m certain I’ve used something similar for characters and moving platforms before (parenting onCollisionEnter etc.)
What’s the obvious thing that I’m missing here? This shouldn’t be confusing me like it is…!