- Home /
Get rigidbody 2D to follow kinematic object
So I have two rigid body 2D objects. The blue box is dynamic, the pink rectangle is kinematic, and can be controlled to move left and right. The box falls on the rectangle and collides fine. My issue is when I'm moving the rectangle left and right, the box doesn't follow along. Instead it just stays still. I tried adding friction with no help. I am using translate to move the rectangle:
transform.Translate(new Vector3(-0.1f, 0, 0));
What am I missing to achieve this??
Answer by GreenCell · Jun 17, 2017 at 05:52 AM
It seems to be working better moving the rigidbody's velocity instead of its transform:
rb.velocity = new Vector3(-2f, 0, 0);
Now the cubes follow the platform as it moves around.
Answer by webcam · Jun 16, 2017 at 05:42 PM
Make the box a child of the platform while it on it. You can accomplish this by shooting a short ray down from the bottom of your cube and seeing if it hits a layer you only put platforms on.
Sounds interesting but this makes it move 1:1 with the platform. Imagine if there was a stack of cubes, I would expect them to be more unstable the higher they are, but this matches exactly the platform's translation making them feel glued on. Also shooting a ray feels inaccurate if I used more irregular shapes or if it's rotated.