Rigidbodys on top of a moving object are not moving with said object.

I have an object that I am moving with

transform.position = new Vector3(Mathf.PingPong(Time.time*sliderSpeed,max-min)+min, transform.position.y, transform.position.z);

It Movies back and forth from one point to the next.
The problem I’m having is that when I place a rigidbody on top of that moving object the rigidbody doesn’t move with it, it does, however, use the moving objects collision and can be pushed by it.
The project I’m working on needs whatever object is on top of it to move with it.

Does anyone know of any ways around it, or if I’m doing something wrong with pingpong.

Both objects are 3d, with mesh collider on one and box collider on the other, have tried making both use box colliders, etc.

Cheers.

Try increasing the angular drag in the rigidbody component, if that doesnt work too well, try increasing the drag, or a bit of both. You may need to set either drag settings to something high, so try a variety of values.

The position calculation you are using is fine and the PingPong is working correctly. Its just the way you are moving the object. When you directly set a transform.position it will calculate collisions but it will skip the physics engine. That is why your top block isn’t moving, because it isn’t feeling any forces. It just slides in the same spot.


For this to work, you will need to add a rigidbody to your platform and set it to kinematic. Then instead of setting the position directly you use Rigidbody.MovePosition(); You can reuse the Vector3 you created:

    private Rigidbody rb;

    public void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    public void Update()
    {
        rb.MovePosition(new Vector3(Mathf.PingPong(Time.time*sliderSpeed,max-min)+min, transform.position.y, transform.position.z));
    }

Now the object will be moved with forces and will interact with other objects. When you are working with rigidbodies, always use MovePosition instead of using position directly, unless ofcourse you really need it for some reason.