• 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 SimonDiamond · Apr 10, 2013 at 11:24 PM · rotationpositionparentchildrelative

Where to find original unity Parent/Child script?

okay so i'm very interested in Unitys original parent-child code/script. I know you can find some scripts in Assets but i'm not sure if any of these involves the parent-child code/script. The reason why i want to see this code/script is because i'm interested how they did the whole child/parent thing.

I would guess they haven't released it for the general public and if that is the case, does anyone know a script that basicly does the same thing as the parent-child function? I got an idea how to do it but i'm pretty much walking in the dark.

To be specific, i mean the way a (child) gameobject copies a (Parent) gameobjects movement, and rotates and moves relative to the (parent) gameobjects movement and rotation

Thanks for reading.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SimonDiamond · Apr 15, 2013 at 09:14 AM

With a little help from Loius here i managed to get it to work the way i wanted. This isn't necessarily the actual physical truth of how parent/child works. But it was the thing i needed to get what i wanted so i thought that i'd atleast post how i solved it to help anyone who might be looking for the same thing as me. I have a camera, and this camera can hold an object. The object will always be infront of the camera. This is the code.

 Vector3 front = transform.rotation * (Vector3.forward * WieldRange);
 WieldedObject.transform.position = front + transform.position;

Wielrange will decide how great the distance is between you and the object you're holding(WieldedObject).

Comment
Add comment · 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
0

Answer by Loius · Apr 10, 2013 at 11:56 PM

It's not a script, it's a physical truth. Like gravity. Child objects just do inherit from their parents.

The nitty-gritty is that (like any 3D app), you render everything with matrices. As you render an object, you add that object's transform to the current matrix. Then you render each of that object's children. As you go back up the tree, you pop off the changes which that child made to the render matrix.

If you somehow want a child that isn't a child but it is (but it's really not), I guess you could:

 class NotAChild extends MonoBehaviour {
   var rotation : Quaternion;
   var position : Vector3;
   var scale : Vector3;
   var tx : Transform; 
   function Awake() { tx = transform; }
 }
 
 class NotAParent extends MonoBehaviour {
   var notChildren : NotAChild[];
 
   function Update() {
     for ( var nac : NotAChild in notChildren ) {
       nac.tx.position = transform.position + transform.TransformPoint(nac.position);
       nac.tx.rotation = transform.somethingprobably( nac.rotation );
       nac.tx.localScale = memberwise multiply( transform.localScale * nac.scale);
     }
   }
 }
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 SimonDiamond · Apr 11, 2013 at 11:23 PM 0
Share

Big thanks! I should have mentioned i'm doing this in C#, but it's no problem. The reason why i'm doing this is because i'm creating a fps controller which can hold objects infront of them. It's really close to unitys child/parent function so that's why i'm asking for it. I'll try this out and get back to you, thank you so much for your help!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

How to hold a child objects position relative to parent as it moves. 1 Answer

Behave like another object is parent? 2 Answers

Camera follow ball along cylinder 1 Answer

Add force to Child while it's parent rotate around something..... 0 Answers

alculate the position and rotation of the object relative to its subobject 3 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