Domanda

I'm using the following code to make my player move along with moving platforms, and it works in that it does indeed make you the child of the platform and move along with it while on it, however the player will move faster than the platform. The platform is moving left then right between two points repeatedly, but the player moves quicker, so will slide along the platform, and you obviously might fall off therefore.

void OnCollisionEnter2D (Collision2D other) {
    if(other.gameObject.tag == "moving") {
        transform.parent = other.transform.parent;
    }
}

void OnCollisionExit2D (Collision2D other) {
    transform.parent = null;
} 

Now I figure that this code is fine because as I have said you become the child of the platform and move along which is all this does.

È stato utile?

Soluzione

Was going to delete this but I thought it'd be best just to leave it here in case anyone has the same issue.

After removing friction from the platform and the player, everything happens as expected, and I can move with the moving platforms without pressing anything.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top