Moving together with an object

I’m working on a restaurant-type game. I’m working on making pizzas and giving it to customers but I can’t figure out how to move an object together with an object.
When you put something on a pizza, I want it to stay there and move together with the pizza so it doesn’t fall off. I tried making it a child whenever it touches the pizza but all it does is makes it look weird. It also falls through the floor. Here is my code

var pizza : Transform;
pizza = (GameObject.Find("Pizza Bun")).transform;
if( == "Pizza Bun"){
	transform.parent = pizza;

Obviously it’s not the full code but it’s pretty much all you need to know.
You’re probably asking for a screenshot of how exactly it looks like when I put it on the pizza.
Normal one is on the right, weird-looking one is on the left

Can someone tell me how to make it actually move with the pizza and not go crazy like in the picture?

I made a video so you guys can stop getting confused and think it’s 2D

This line won’t work:

transform.position = pizza.transform.position;

The reason that wont work is because the pizza’s transform is one little dot, typically right in the middle of the object. So as soon as you set the topping’s position to the position of the pizza, it will snap all the toppings to the center of the pizza.

The easiest way to fix this is to just make it a child. You said you already did this but it made it look weird. That is probably because the pizza is scaled. If you scaled the pizza and then attach a child to it, the child will take on the parent’s scale and become weird looking.

You need to make your pizza uniformly scaled if you scale it at all. It needs to be something like 1x1x1 or 2x2x2 or 1.3x1.3x1.3. This way the toppings will scale uniformly as well.

You need to set the position of the topping onto the pizza

transform.position = pizza.transform.position

something along thoes lines, you might need to tweak it allit bit but it looks like it’s in 2D so this should be fine.

Hello my friend. Your pizza looks delicious.

One solution is as the poster above mentions:

transform.position = pizza.transform.position;

Another way to manage it would be to make the “Pizza” the parent of the “Toppings”. Then you can set the toppings with a local position. This way the toppings follow the pizza in local space.

Here is the official tutorial on Heirarchy and Parent-Child relationships:

I hope that helps and wish you much success in the pizza business.

  • Cranky Franky