- Home /
Moving platform on Unity 2D not working
So, I've searched around in a bunch of different places but I can't seem to figure out the correct way of implementing a moving platform.
I'm making a simple 2D platformer using Unity's physics system for simplicity sake, with my player being a dynamic Rigidbody2D on which I set the velocity every FixedUpdate.
The tutorials I've seen regarding moving platforms in this scenario says to make the player a child of the moving platform, and also change it's rigidbody to kinematic. I did it in a way that whenever the player goes on top of the moving platform, it's attached as a child of the object and its rigidbody becomes kinematic. However, by doing so the movement using velocities stop working, so I made another check on the MovingPlatform script to see if the player is moving or jumping and if so his rigidbody becomes dynamic.
Everything seemed to work fine at first, but whenever the platform is moving downwards and I move the player horizontally he starts a "falling" animation and the behavior gets messed up, probably because the player starts to be dynamic and gravity is affecting him again and the platform moves before the player moves (it's my guess at least)
Does anyone have a better idea on how to implement moving platforms with rigidbodies and Unity's 2D physics?