Moving 2D platform is not working right! Help
Hello :)
I'm having a problem with my moving platforms in 2D Game. 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?
P.S. I tried to make a Friction Material with Friction of 10 and give my player friction of 5 at the same time.
Answer by PersianKiller · Feb 02, 2018 at 04:07 AM
you don't have to move your player with the platform.just make the player child of the platform .so when the platform moves the player will go with it .
//platform script
void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.CompareTag( "player")) {
other.gameObject.transform.parent = transform;
}
}
void OnCollisionExit2D(Collision2D other){
if (other.gameObject.CompareTag( "player")) {
other.gameObject.transform.parent = null;
}
}
so if an object with player tag collides with this platform,it will be child of this .
If he's using a ridgidBody, this wont help much. If you're character is using a ridgidBody you will also need to enable is$$anonymous$$inematic so that it will not be driven by the physics engine while it is on the platform.
I only mention this because of the comment about Physics $$anonymous$$aterial with Friction of 10. Not sure if that implies a physics based controller or not.
I'm using Rigidbody2D for the player and move the platform with transform.translate and there's no problem.