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 chenkimlim · May 24, 2013 at 01:30 PM · parentchildpivot

How to be sure that the parent's position is the same is the child's position?

Hi All,

I have a question here. I have a list of boats which is the parent and 25 flockers who are the child of each boat. However, it seems like right now, when the boat is sailing, the flockers follow the direction of the boat but not the position of the boat. I would like to have the flockers on each of the boats and follow the coordinates of the boats as they sail as if like they are on the cruise.

This is what I have done:

 for (int j=0; j<4; j++){
         for (int i=0; i<25; i++){
         int numberOfRows = (int)(Mathf.Sqrt(25));
         int a = i/numberOfRows - numberOfRows/2;
         int b = i%numberOfRows - numberOfRows/2;
         Transform trans =  FleetManager.getBoatTransform(j);
         Vector3 pos = new Vector3(0.0f, 0.0f, 0.0f);
         pos =  new Vector3(a, 0.0f, b);
         GameObject go = (GameObject)Instantiate(flockerPrefabs[0], pos, Quaternion.identity);
         go.transform.parent = trans;
         go.transform.position = pos;
         this.transform.parent = null;
         }
     }

 public Transform getBoatTransform(int id){
     BoatAnim[] array = boats.ToArray();
     return array[id].transform;
 }
 
 





There were a lot of suggestions that I have looked up:

(a)"•When parenting Transforms, set the parent's location to <0,0,0> before adding the child. This will save you many headaches later. " from http://docs.unity3d.com/Documentation/Components/class-Transform.html

(b)"Move the parent (via the inspector) so that the children are in the right place the if the pivot was 0, 0, 0. Then, unparent the children, set the parent to 0,0,0, and reparent" from http://answers.unity3d.com/questions/18637/change-pivot-of-parent-game-object.html

Any suggestions to make the flockers on the boat and sail according to the boat's position?

Thanks.

Kim

Comment
Add comment · Show 6
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 chenkimlim · May 24, 2013 at 01:21 PM 0
Share

Hi,

Btw, at the inspector, I have also set the boats and flocker$$anonymous$$anager's position to be 0,0,0. What else that I could have missed or mistakenly done?

Thanks.

avatar image robertbu · May 24, 2013 at 01:37 PM 0
Share

What scripts are attached to the 'flockerPrefabs[0]' prefab? If you replace this prefab with a simple game object like a sphere, do you still have the problem?

avatar image chenkimlim · May 24, 2013 at 01:45 PM 0
Share

Hi,

It is a Flocking script. I have flocker$$anonymous$$anager which controls a group of flockers and flocking script which controls each of the flocker.....

Thanks.

avatar image robertbu · May 24, 2013 at 01:57 PM 0
Share

The parent/child relationship is fairly straight forward. I cannot see how you would get direction but not position unless there is an issue with either the flocker$$anonymous$$anager or with the flocking script.

avatar image chenkimlim · May 24, 2013 at 02:06 PM 0
Share

In my boat prefab, there are "shape" and "plane" added to it as children. I added the plane as a mesh collider so that the flocker will not fall into the sea. The shape basically comes by default when I downloaded from free$$anonymous$$odel.

$$anonymous$$ust the boat prefab and shape be in the same position and rotation? As in all 0,0,0?

Because when the boat sails, the flockers obviously follow but as though like with an offset point far behind the boat and not exactly with the boat. Would it be all the related Gismos are not aligned?

Any further hints? Thanks.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

How to set pivot point to the parent 1 Answer

tank turret rotate without messing up 2 Answers

change pivot of parent game object 1 Answer

Calling a function of another object's child? 1 Answer


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