Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Aleks6010 · Jul 21, 2014 at 05:28 AM · movementobjects

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(Collision.gameObject.name == "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.

http://i.imgur.com/kIcJ09e.png 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?

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RafaelCN · Jul 21, 2014 at 07:02 AM 0
Share

Try lock the rotation constraints if you are doing the moviment of the objects with Rigibody.

avatar image Aleks6010 · Jul 22, 2014 at 12:33 AM 0
Share

I already tried making it child and it just falls off, doesn't move together. It's 3d btw.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by drex150 · Jul 21, 2014 at 07:11 AM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Franky_Cranky_Man · Jul 21, 2014 at 07:14 AM 0
Share

Yes you are right about it snapping to the center of the object. I agree as we both mentioned making the toppings a child is really the way to go here.

avatar image Aleks6010 · Jul 21, 2014 at 11:58 PM 0
Share

It falls off, also it's 3D

avatar image
0

Answer by Mrslayer01 · Jul 21, 2014 at 05:37 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aleks6010 · Jul 22, 2014 at 12:07 AM 0
Share

It's 3D, also won't that move meat into the center of the pizza?

avatar image
0

Answer by Franky_Cranky_Man · Jul 21, 2014 at 05:59 AM

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:

http://unity3d.com/learn/tutorials/modules/beginner/editor/the-hierarchy-and-parent-child-relationships

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

  • Cranky Franky

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RafaelCN · Jul 21, 2014 at 07:01 AM 0
Share

Your answer is funny hahaha :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Select/Drag/Drop Objects with a mouse 0 Answers

Simulating Marble Blast Gold: A script to make a character as a marble roll forward, mouse turns screen? 2 Answers

Need a help for movement Script! 1 Answer

Rotating a object towards a direction then move it 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges