- Home /
2D Moving platforms is slippery!
Hello :)
I'm having a problem with my moving platforms It seems like it need to move every time when the platform is moving to stay on it. But I want to make it like classic way, that if you are standing on moving platform you don't need to move to stay on it What can cause the problem?
I tried to make a Friction Material with Friction of 10 and give my player friction of 5 at the same time.
A few ways to go about this. If you don't want to use a super high friction coefficient, then making the player object a child of the platform when they are standing on it might be an acceptable solution.
I'm not sure how can I make this How can it be done?
How are you moving your platforms? Are you just moving the transform or applying forces to the platform.
It also sounds like maybe the player isn't touching the platform and thus is not being moved with it. Try putting a Debug.Log statement in OnCollisionEnter (or the 2D variant) in your player controller script and see if you get a collision.
Answer by The_Icaruz · May 18, 2018 at 05:55 AM
In my game I've added this line of code in my Player Controller Script and add the Tag "MovingPlatform" to the platforms that are moving.
// Check if the Player is on a Platform and set the Player as child of the Platform
void OnCollisionEnter2D (Collision2D other) {
if (other.gameObject.tag == "MovingPlatform") {
transform.parent = other.transform;
}
}
// Check if the Player leaves a Platform and set it back out of Parent
void OnCollisionExit2D (Collision2D other) {
if (other.gameObject.tag == "MovingPlatform") {
transform.parent = null;
}
}
Answer by Obsessi0n · Feb 02, 2018 at 12:06 AM
Try to do this: run this in an update -> If player is colliding with the platform then the position.x of the player should be = the position.x of the platform.
Answer by Caliber · May 18, 2018 at 09:20 AM
Depends a bit on how your collision detection works. In this tutorial
the dev has the same issue, and shows how to solve it (using raycasts).