Player rigidbody slides off moving platform

Hello everyone

I’ve gotten myself stuck on a problem for a while now. My player, which is controlled using my own script and a rigidbody2d, slides off my horizontally moving platform when standing on it. The hope is to have my player move around freely on the platform while it’s moving, without sliding.

I’ve implemented the use of Rigidbody2D.MovePosition() to move the platform as it was suggested here: Rigidbody on a platform - Questions & Answers - Unity Discussions, but the player still slides off. Perhaps I’m missing something to make this work?

I also tried adding the player as a child of the platform when standing on top of it, but that resulted in really clunky movement for the player. I also don’t think it’s a very logical solution so I’d like to avoid it if possible (unless anyone can convince me otherwise).

Last I’ve tried my own solution, which was to add the velocity of the platform to the player’s, but that didn’t seem to work either. I’m not entirely certain why it didn’t work or if I have made some coding mistake, but the logic seemed right I thought.

So if anyone could help me figure this out in a logical and clean way, I’d be very grateful!

Ps: If you need me to supply any of my code or a video of what’s going on, let me know.

Usually, some of the better options do still involve making the platform a parent of the character for this sort of thing. That way, when the platform begins moving, the player moves exactly with it, as though it were simply stationary ground the player is standing on.

What causes problems with this easily, however, is making the transition between a moving platform and a stationary one (and vice versa). When the parent of a physics-driven object changes, the object keeps its current velocity… and adds it to the parent’s. As a result, landing on a platform moving the same direction means suddenly shooting forward at incredible speed.

It does take a little tweaking to get the exact result you want, but unless the platform leans into its motion to push the character standing on it or, ideally for gameplay, make the character a child of the platform, you’re simply adhering to the laws of physics.