• 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 pudumaster · Jan 26, 2014 at 08:36 AM · c#rotationinstantiatequaterniondirection

Instantiated objects always facing the center

alt text

As shown in the picture above, I instantiate the same object multiple times each at a random position around the circle. I just can't get the objects to always be facing the center of the circle. Iv'e tried Quaternion.LookRotation (Vector3.zero) since the position of the circle is (0, 0, 0), but it didn't work.

Any suggestions?

Comment
Add comment · Show 2
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 getyour411 · Jan 26, 2014 at 08:38 AM 0
Share
avatar image pudumaster · Jan 26, 2014 at 08:54 AM 0
Share

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jan 26, 2014 at 08:41 AM

LookRotation takes a direction not a position. You can solve your problems one of two ways. Either you can use Transform.LookAt() (w$$anonymous$$ch does take a postion), or you can calculate a direction vector for LookRotation(). If the position to look at is always the origin (Vector3.zero), then you can use the negated position you use for placing your object. Without seeing your code, it is hard to be specific, but say you place one of the arrows at (0,0,5). You could do somet$$anonymous$$ng like:

 var pos = Vector3(0,0,5);
 Instantiate(prefab, pos, Quaternion.LookRotation(-pos));

Again, the LookRotation() will take the negative of whatever position you use to place your Instantiated object.

Comment
Add comment · Show 6 · 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 pudumaster · Jan 26, 2014 at 09:04 AM 0
Share
avatar image robertbu · Jan 26, 2014 at 09:54 AM 0
Share
avatar image pudumaster · Jan 26, 2014 at 11:10 AM 0
Share
avatar image robertbu · Jan 26, 2014 at 02:56 PM 0
Share
avatar image pudumaster · Jan 26, 2014 at 03:20 PM 0
Share
Show more comments
avatar image
0

Answer by limaoscar · May 18, 2018 at 10:21 AM

i know t$$anonymous$$s is an old post but if anyone still needs to do somet$$anonymous$$ng similar here is some code.

void DrawCircleVectors(int points, float radius, Transform center1) { float slice = 2 Mathf.PI / points; for (int i = 0; i < points; i++) { float angle = slice i; float newX = (float)(center1.position.x + radius Mathf.Cos(angle)); float newz = (float)(center1.position.z + radius Mathf.Sin(angle)); Vector3 p = new Vector3(newX, center1.position.y, newz); GameObject go = Instantiate(prefab,p,Quaternion.LookRotation(p,center1.position)); go.transform.SetParent(center1); } }

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.

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

19 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

Related Questions

Particle System Instantiate's With Original Rotation - C# 1 Answer

Rotating a certain axis offsets the other ones? 1 Answer

Flip over an object (smooth transition) 3 Answers

i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 0 Answers

Object instantiate, Projectile problems 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