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 moodiey · Feb 01, 2017 at 07:28 PM · rotationinstantiateloop

Clone positioning inside loop

Hello. I have an empty gameobject with a script attached. This script instantiates a set of boxes along X and Y with the use of a loop (looks like a solid brick wall). My problem is that I want to place many of these walls, and rotate them in the scene however I want, but no matter how I rotate the empty game object in order to rotate the WHOLE wall, the individual bricks just grab the local rotation and just use it as its own, so the wall is always oriented a certain way regardless of how i rotate the container. See screenshot

The problem is actually not the rotation, technically the bricks rotate the way i need them to. I think i need to MOVE them in relation to the last instantiated clone, but i dont know how to get a reference to that.

Clone script:

     public Transform brick;
     public GameObject spawn1;
     private float x;
     private float y;
     private Vector3 pos2;
 
     void Start()
     {
         for (y = 0; y < 10; y++)
         {
             for (x = 0 ; x < 10; x++)
             {
                 Vector3 pos = transform.position;
                // pos2.x = x + //some reference to last instantiated clone here?/;
               //  pos2.y = y + //some reference to last instantiated clone here?/;
                // pos2.z = z + //some reference to last instantiated clone here?/;
                 Transform brickclone = Instantiate (brick, pos + new Vector3(x, y, 0), transform.rotation);
              //   brickclone.transform.position = ??
             }
         }
     }
 }

This instantiates a straight wall provided the container rotation is 0,0,0. Once i rotate the container, the individual bricks rotate but the wall is always oriented the same way. How do i get the whole wall to rotate based on the containers rotation and have the bricks line up straight?

alt text

v.jpg (70.0 kB)
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
1
Best Answer

Answer by FortisVenaliter · Feb 01, 2017 at 07:46 PM

You need to rotate the local positions when you are instantiating it. For example:

 Transform brickclone = Instantiate (brick, pos + (transform.rotation * new Vector3(x, y, 0)), transform.rotation);
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

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

7 People are following this question.

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

Related Questions

Network.Instatiate Problem 0 Answers

Simple rotation script. (loop) 3 Answers

I am trying to make a gun recoil with an animation and in this script it only runs after the first mouse click. This is probably an easy fix I just can't seem to wrap my head around it. This is my script. 1 Answer

Edit textmesh of prefab child object after instantiate of parent during a loop C#. 1 Answer

Instantiate objects in a specific order 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