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 uanmanarmy · Jul 03, 2014 at 01:22 PM · transformpositionobjectsreference

Position of Instantiated Objects from a reference

Hi, I want to instantiate objects with an equal distance from a reference

So for example if my reference is situated in the (0,0,0) and if I have 1 obj, then it's center will be in the position of the reference.

if i have 2 objects than, the sum of then they will also place themselves auto. according to the reference.

Here is the example

alt text

безымянный.jpg (37.5 kB)
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 Denvery · Jul 03, 2014 at 01:45 PM 0
Share

If I have understood correctly, you want to set the position during instantiating? http://docs.unity3d.com/ScriptReference/Object.Instantiate.html

avatar image HarshadK · Jul 03, 2014 at 01:46 PM 0
Share

What exactly do you need? Do you need logic? Do you have any code you've written that you can put here?

avatar image Manco Capac · Jul 03, 2014 at 05:06 PM 0
Share

Okay, if i understood correctly then u want your instantiated object a specific distance away from an object, or the previous object instantiated, and they will instantiate both ways along the reference point.

If that is so, then var refPos : Vector3; var noOfObjects : int;

 function Instantiate (){
      var x : Transform;
      x = Instantiate( OBJ , refPos , Quaternion.identity );
      noOfObjects ++;
      x.transform.position = THE DISTANCE BETWEEN THE OBJECTS/noOfObjects)
 }


i didnt test this and u since i dont know what u want i cant give u a more specific script

avatar image uanmanarmy · Jul 04, 2014 at 10:22 AM 0
Share

@$$anonymous$$anco Capac, you are right I wanna do what you told.

avatar image uanmanarmy · Jul 04, 2014 at 10:25 AM 0
Share

@for all, I know how to instantiate objects, I just need this algorithm of finding the middle of sum of lengths of nr of objects I have div by 2, and to put them on both sides from reference (as I told for example 0,0,0.

So if I have one object it will be placed on , 0,0,0 .
if I have 2 objects they will be placed, one at -1, 0, 0 the second one at 1,0,0.

Something like this.

Show more comments

1 Reply

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

Answer by Noob_Vulcan · Jul 04, 2014 at 10:33 AM

Well just to be very simple ...You can make prefab of these 2 , 3 and 4 obj , and instantiate them . Center of all the Objects will be at instantiation position.

I hope this is want u want

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 uanmanarmy · Jul 04, 2014 at 11:24 AM 0
Share

How can I calculate the length of all objects ?

avatar image uanmanarmy · Jul 04, 2014 at 01:00 PM 0
Share
 private List<GameObject> item = new List<GameObject>();
     public GameObject itemPrefab;
     int numberofObjects = 0;
     public float distance;
     void Start () 
     {
         
         for(float i = 0 ; i <5 ; i++)
         {
             numberofObjects ++;
 
             item.Add (Instantiate(itemPrefab, new Vector2(0.0f,2.0f), Quaternion.identity) as GameObject);
 
             distance = Vector3.Distance (item[0].transform.position, item[numberofObjects -1].transform.position);
             float temp = distance/numberofObjects;
 
         }

}

I got something like this for now, I have the distance, but as you can see Im getting the distance after every iteration.

Now I need to place them and solve that distance .

Any Ideeas?

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

24 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

Related Questions

NavMeshAgent places transform incorrectly 1 Answer

Transform position in animated model 1 Answer

Vector3.Slerp not working 2 Answers

Move object while rotating another one 1 Answer

How do I use one GameObject's properties in a different GameObject's script? 0 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