- Home /
How to move multiple dynamic gameobjects with one moving platform which is controlled by the player
Hi, I am making this mobile game in Unity, where the main purpose is that there are every x seconds falling boxes and you, as a player, are trying to move with the platform so you build on top of themselfs as much boxes as possible (you can see the screenshot so you get better picture of what i mean). The falling boxes are dynamic type and the moving platform is kinematic.
void OnCollisionEnter2D(Collision2D something)
{
if (something.transform.tag == "Player" || something.transform.tag == "SpawnedBox")
{
transform.parent = something.transform;
}
}
void OnCollisionStay2D(Collision2D something)
{
if (something.transform.tag == "Player" || something.transform.tag == "SpawnedBox")
{
transform.parent = something.transform;
}
}
void OnCollisionExit2D(Collision2D something)
{
if (something.transform.tag == "Player" || something.transform.tag == "SpawnedBox")
{
transform.parent = PlayingField.transform;
}
}
So far i have used the parenting method when collision (using all three worked the best so far for me). The problem it is kinda glitchy. When there are more boxes, the ones that are lower start to slide of making is impossible to score more than 20 points. When I used only OnCollisionEnter2D and OnCollisionExit2D, when moving the platform, the boxes lost connection and everything fell. I hope there isn´t any question like that somehwere already. I have found just the ones with "player on moving platform". Trying to find a solution for a weeks now.