Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ki4Chan · Sep 14, 2017 at 07:53 AM · rotationtransformparent and child

Instantiated object's transform changes according to parent object's rotation

I have an Object(parent) having 4 spawn points around it which spawns stars. In the game, Parent object rotates but the Spawned stars don't move according to Parent objects rotation. I have tried all the suggestions people have given in the forum.

     public GameObject starPrefab;
     private GameObject newStarPrefab;
     public Transform[] starSpawnPoints;
 
     void Start () {
         if (!GameObject.FindGameObjectWithTag("Box"))
         {
                 RandomPoint();
         }
     }
 
     void RandomPoint()
     {
         int randomIndex = Random.Range(0, starSpawnPoints.Length);
 
         for (int i = 0; i < starSpawnPoints.Length; i++)
         {
             if (randomIndex == i)
             {
                 newStarPrefab =  Instantiate(starPrefab, starSpawnPoints[i].position, Quaternion.identity);
                 newStarPrefab.transform.parent = gameObject.transform;
             }
         }
     }

I have added this script to the Parent object which rotates after spawning.

Comment
Add comment · Show 1
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 hexagonius · Sep 14, 2017 at 09:53 AM 0
Share

You're saying the parent has this script, the spawn points are it's children and after creating stars and attaching them to those they don't normally rotate with it?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Sep 14, 2017 at 02:04 PM

Hello @Ki4Chan !

As i can see, you instantiate the objects with position starSpawnPoints[i]. As i understand, this transfomrs are the spawns transforms that should move when the parent rotate.

In the scene, do you see the spawns moving? I can't tell you why is happen this, but try this things to check:

Try to chech if the spawn poitns move when parent rotates. before Instantiating the starPrefab, do a

 foreach (Transform TransformSpawn in starSpawnPoints)
 {
  Debug.Log (TransformSpawn.position + " - " + TransformSpawn.name)
 }

To check all SpawnPoints position. Or even try it in the Update if the is rotating all time

You can also try to Instantiate directly to be the child of a transform, using this:

 Instantiate (starPrefab, transform);

If this helps, upvote and check the answer!

If need more help, give more info and use the @tormentoarmagedoom

Bye :D

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 Ki4Chan · Sep 14, 2017 at 02:53 PM 0
Share

Bro, the same code is working. All I did is closed Unity and reopened it. Thank you for your precious time.

avatar image tormentoarmagedoom Ki4Chan · Sep 14, 2017 at 04:37 PM 0
Share

Then close the question :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

108 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

How to rotate a child where its parent has another Z rotation? | Issue when rotating towards the mouse after it goes on the other side of the player 0 Answers

I'm interpolating an object between positions and rotations. Now I need to make sure it happens in front of the camera. 1 Answer

Player not facing the mouse correctly 1 Answer

GameObject facing fowards 1 Answer

eulerAngles.y always returns 179.9999 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