• 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 itscoolbro · Sep 21, 2013 at 08:27 AM · angleunity 4mathfarc

Instantiate objects in an arc shape

I have this function that moves the object around a circle:

 void arrangeCardsInHand(Player newPlayer){
         
         int numCards = newPlayer.Hand.Count;
         var centrePos = new Vector3(0, 300 ,0);
         
         for (var cardNum = 0;cardNum < numCards;cardNum++) {
             var i = (cardNum * 1.0 / numCards);
             
             //angle in radians, full circle has a radian angle of 2PI, so we find the radian angle between 
             //2 of our points by dividing 2PI by the number of points
             var angle = (float)(i * Mathf.PI * 2);
             
             var radiusX = 10000.0;
             var radiusZ = 4300.0;
             
             var x =(float)( Mathf.Sin (angle) * radiusX);
             var z = (float)(Mathf.Cos (angle) * radiusZ);
             
             var cardName = newPlayer.Hand[cardNum].cardName;
             GameObject.Find(cardName).transform.position = new Vector3(x, 0 ,z) + centrePos;
             
             
         }
         
     }

I want the cards to be arranged in the top arc of the circle (1/4 of a full circle).

I have no idea how to work out the starting and the ending point into this formula tho. I'm also open for other ideas (like beziers or w/e) if you think this is not the best solution for what I want to do.

Any answer is appreciated.

Comment
Add comment · Show 3
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 Fattie · Sep 21, 2013 at 08:48 AM 0
Share

You should be doing this using game objects in Unity.

Never calculate anything.

Have your object that makes the card....

Now have anther object (perhaps called "spinner"), put "spinner" where you want, at the center of the circle.

Put the card-maker inside spinner, and move it out whatever radius you want. It is trivial to adjust all this in the editor

now simply use

"Rotate"

.
to rotate the spinner

http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

it couldn't be easier. Why use machine code -level program$$anonymous$$g when you have a whole astounding game engine at your disposal?

avatar image itscoolbro · Sep 21, 2013 at 09:02 AM 0
Share

You're right, man. This is a way better solution than what I was using. Although it requires a little bit of tinkering because my actual implementation is a bit more complicated but I will try this method out ;)

avatar image Fattie · Sep 21, 2013 at 11:18 AM 0
Share

Go for it. it's great because you can just "move around" that "holder" object, and so on. It's the only way to fly.

1 Reply

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

Answer by DaveA · Sep 21, 2013 at 08:30 AM

Something like:

var angle = (float)(i Mathf.PI 2) + Mathf.PI / 4; // add 45 degrees

and adjust i to end at 135 degrees (Mathf.PI * 3 / 4)

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 itscoolbro · Sep 21, 2013 at 08:43 AM 0
Share

Yeah! almost there :D This worked for me:

var angle = (float)(i $$anonymous$$athf.PI 0.5) - $$anonymous$$athf.PI / 4;

Thanks, brosef!

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

17 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

Related Questions

How can I calculate the Vector3 b using Vector 3 a pos with an angle? 1 Answer

Find the right angle for certain distance with arc effect? 1 Answer

Velocity to 2D rotation (angle from velocity vector with atan2) 1 Answer

How to throw a rigidbody along line renderer? 1 Answer

tangents from angle gives weird results 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