- Home /
Piling up objects and transporting them
Hello Everyone,
I'm trying to work on a mechanic where the player is holding a box and they need to catch and pile pizzas that randomly fall from the sky. In order to make this work I have been trying to parent each pizza prefab to the box or another pizza through the two colliders touching, recognizing the gameobject's tag and creating a parent-child relation so that the pile of pizza follows the player moving. (the player can only move on a constrained horizontal axis). The mechanic works, but I am having two issues with it:
-Since it's a parenting based mechanic, the pizza prefabs remain still once piled. I am activating the kinematic function on their rigidbody once they touch the collider of the last piled pizza. This does not allow to have a more "realistic" effect where the pile has a small delay in following the player's movement (especially at the top). I had to do this so that the pizzas would not fall when the player hit the border of the axis where they can move.
-The second problem comes from the fact that I'm using colliders to make this work. If you have a large pile of pizzas and try to catch one with the side of the pile, this sticks on the side and does not keep falling as it should. I've tried giving multiple colliders to the pizza prefab, but it still acts in the same way.
Please let me know if you have any suggestions on how to improve this. I believe that a physics based mechanic would work the way I want, but the problem is that, once caught, the pizzas slide down when the player moves.
Here is a video showing the issue: https://www.youtube.com/watch?v=Xh4yBkHN9ws&feature=youtu.be
Thank you for your time!
Answer by hexagonius · May 17, 2020 at 06:58 PM
I once made a character carry boxes which should wiggle a bit due to the players movement. I did this by joining then via custom joints that uses springs and a certain angle threshold
It depends on you came, but you probably need to calculate HOW the pizza touched any collider. Was it the top most? was it any other pizza? was it from the top or the side?
The bigger question is, why use physics. There's no unpredictable state here, no simulation needed. You know where the pizzas are, you know where the player is, you know when a pizza that falls will meet a pizza that's being carried by the player. And above all, that's 2D with a 3D visual representation. You could just calculate by the widths and heights how they would overlap and handle them accordingly. Depends on the gigglyness of the pile of course. If that's important, 2D would still do it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612234552im_/https://answers.unity.com/themes/thub/images/avi.jpg)