- Home /
Player Slows Down When Entering a Moving Platform
For context, the code I currently have is as follows:
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "MovingPlatform")
{
transform.parent = other.transform;
}
}
void OnCollisionExit2D(Collision2D other)
{
if (other.gameObject.tag == "MovingPlatform")
{
transform.parent = null;
}
}
This is currently a part of my player script. On execution, the player enters the moving platform, becomes a child of the moving platform, and moves with the platform. Once you jump, run off the edge, or break collision in any other way, the player is no longer a child of the platform, and will not move with the platform anymore.
The problem is that while the player is a child of the game object, rather than moving at the normal player speed (7 units per second horizontally), they'll inherit whatever speed the platform is moving at (in this case 3 units per second, horizontally) and will run at that speed when you input for either right or left movement while the player is still a child of the moving platform.
I'm hoping to find a solution where the player is able to run at their normal speed, but still be pulled horizontally along with the platform as well.
Your answer
![](https://koobas.hobune.stream/wayback/20220612164205im_/https://answers.unity.com/themes/thub/images/avi.jpg)