Unity player not sticking to a moving platform when using kinematic platform type

I’m working on 2D Unity game. I want to make a moving platform on which player can stand, move, jump.

Player is dynamic Rigidbody2D with this settings

6804350--789425--1.png

Platform is kinematic Rigidbody2D with this settings

6804350--789428--2.png

For moving player I’m using velocity

private void FixedUpdate()
{
   rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

}

For moving platform I’m using MovePosition

private void FixedUpdate()
{

rb.MovePosition(transform.position + transform.right * Time.deltaTime);

}

Player doesn’t stick on platform, when platform gone player will fail down (because of gravity)

The Player must be dynamic Rigidbody2D, the platform does not have to be kinematic Rigidbody2D.

But when I remove physics from platform (also set player to be child of platform) player moves slower on the platform than on the ground and there is jittering that’s why I made platform kinematic rb

Can someone tell me why player not moves with platform when both uses physics? And how to fix this

Thanks

One way is to parent the player to the platform.

Another way is to connect the player to the platform using a FixedJoint2D, then destroy that when he leaps or falls off.

Another way would be to implement your own tracking that you’re on a platform, each frame use the motion of the platform between previous to now and combine that with player input to move the player.

There’s probably Youtube tutorials with even more crazy ways to do it.

PS - here’s a less-than-three-minute video using parenting:

1 Like

Can you please help me with this solution?

I’m moving the player the same way and I set the platform moving the same way, but my player speed is slowing (less when moving with platform direction) and there is some chopping when the player moves on the platform. I want a player on the platform to move the same speed as on the ground (That moving is done using platform kinematic and moving with MovePosition, but in that case I have problem sticking a player on the platform).

6810407--790517--20210206_215246.gif
Platform kinematic, moving with MovePosition

6810407--790520--20210206_215557.gif

Platform without physics, moving with transform.position and Player parenting to platform ()

Hi,

Both rb.velocity, and transform.position are relating to the global speed, and position, which is the players local speed + the platform speed. So it’s expected behavior. If you instead wish your player should move relative the platform it’s parented to, use relative force, or positions instead. Or just add the platform movement to the equation when the player is moved on the platform.

Say you want to achieve this with physics only, it’s the friction value which can be used to make it “stay in place” to some extent. So, if both objects use a material with high friction, the player would “rest” relatively to that platform.

However, as soon as an abrupt acceleration occurs, your player would fall victim to its momentum. For instance, suppose the platform moves horizontally only, and it’d slow down or even change direction quickly, then the player might slide off the platform, or at least closer to the edge.

If you need more control, it might be better to not use a dynamic rigidbody, but a kinematic one and control the entire movement via code.