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 Deathscreton · Jan 11, 2012 at 07:26 AM · parentgames

Parenting and Scripting

I'm following a old guide/tutorial for Unity3D (in which it still believes the scripting program used is UniSciTE). While old, I've been following along well enough to understand the content and place my foot in the door for Unity.

In any case, I've come to a brick wall. I'm able to climb the wall, but I'm doing so blindly.

The book as just introduced me to Scripts and basic parenting (I say basic because the book does not explain the actual feature until later into the book). We've just passed the bases of learning basic transformation tools. It explains the way the engine reads the script and why two transformation functions cannot be used in one script at the same time. So it has me create an empty (which I name Cube Parent) and attach a script (one used for moving) to it, while the script for rotating is attached to the actual object (which in this case is a cube simply named "Cube").

The code for the moving is as follows:

     #pragma strict
 
 function Start () {
 
 }
 
 function Update () {
 
 
 //transform.Rotate(0,50 *Time.deltaTime,0);
 transform.Translate(0,2 *Time.deltaTime,0);
 
 }

The code for the rotate is similar, with the translate commented out and the rotate not.

Now this works, I run it, the cube increases and spins. However, this is where I'm lost. How does the empty object and the cube suddenly become grouped without me ever doing so? I thought maybe it was the way he named the empty object (Cube "Parent") which makes the game automatically link the two. So trying this, I create a sphere and a "Sphere Parent". I attach the two scripts the same way and the sphere moves. So I figure I had it right. Deciding to try one more thing, I delete the pair, re-create them to avoid errors, then attach the move script to the parent. If they're grouped, then the sphere should move without the script attached to itself. The sphere does nothing.

So here I am, confused like a bat out of hell, not understanding why what he did, did what it did.

Any and all help would be appreciated!

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

1 Reply

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

Answer by adrenak · Jan 13, 2012 at 06:56 PM

Hi Deathscreton, hierarchy in Unity is based on parenting. You make an empty gameobject called lets say 'P' and add the script to it with rotation commented out, click on P in Hierarchy so that you can see it in scene window and run the game Without 'maximise on play'. You can see that it moves up as it should.

Now the thing is that lets say you make a cube and drag it to P,which is the empty that you had created with the translate script. Since cube is now a child of P, wherever P goes, cube goes with it, however P rotates, cube rotates with it. When you add the script for rotation to cube, all that cube ( the child ) has to do is rotate along its local axes. The job of making it move is done by the parent P.

Try this out : Apart from the rotation script, also add the translate script to cube. Now select P so that you can see it in the Game Window and run the game. You will see that the parent P moves as before but the child cube moves with double the speed in the same direction as the parent. This is again because apart from its own motion, the parent is also moving it. Its like a train is moving towards North with a speed 'x' and you are inside the train and running towards North with a local speed 'x',so a person seeing you from outside standing 50 meters away sees you running towards north with speed 2x.

As far as the naming convention that you thought of that the word 'parent' in the parent name is used so that it is detected by Unity is incorrect. You can name the parent any thing and the child anything else, just make sure that you Drag the object that you wish to be the child on to the object you want to be the parent, on doing this an arrow will show up on the left side pf the parent, which when clicked will show you the children.

Hope this helps!

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 Deathscreton · Jan 13, 2012 at 07:18 PM 0
Share

$$anonymous$$uch appreciation! I couldn't figure it out for the longest! Hopefully I can come back here and answer similar questions and help everyone else as well.

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

Multiple Cars not working 1 Answer

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

camera focus on sphere 1 Answer

Scripting error comes up when I press play 1 Answer

How To Stop Destroyer From Destroying? 2 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