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 alexjolig · Apr 25, 2018 at 07:37 AM · rotationtransform.positionmove an object

move multiple 2d items in a circle around a fixed point

I'm trying to move some objects around a center object in a queue. I tried this solution at it works great for one object, thanks to heads up from this answer:

 public class RotateAround : MonoBehaviour {
 
     public float RotateSpeed = 5f;
     public float Radius = 1f;
     public Transform Target;
 
     private Vector2 _centre;
     private float _angle;
 
     private void Start()
     {
         _centre = Target.position;
     }
 
     private void Update()
     {
         _angle += RotateSpeed * Time.deltaTime;
         var offset = new Vector2(Mathf.Sin(_angle), Mathf.Cos(_angle)) * Radius;
         transform.position = _centre + offset;
     }
 }

As I said it works great for one object. But if I try to use it for multiple objects, they just go on top of each other. I tried some ways to solve the issue but failed.

How can I edit this so that I can set a new offset for each object?

Thank you.

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

2 Replies

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

Answer by alexjolig · Apr 25, 2018 at 08:42 AM

I fix the issue by adding a public Range and use it to set angle in Start method like this:

 [Range(-3.14f, 3.14f)] public float AngleRange;
 private void Start()
 {
     _centre = Target.position;
     _angle = AngleRange;
 }

Then I set proper values for each items.

Thanks to @Captain_Pineapple for the idea!

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

Answer by Captain_Pineapple · Apr 25, 2018 at 08:13 AM

Hey there,

simply add a different start value for the variable _angle. For example add the line:

 _angle = Random.Range(-3.14f,3.14f);

to your Start() function. This randomizes your startangle and thus your starting position.

Edit:

I missed the queue part in your question... This is something that you should do in a script that is instantiating your rotating objects. Simply divide the full circle by the amount of objects you want to rotate and set these as the starting angles of your objects. Something like the following:

 int amountOfObjects = 10;
 float fullCircle = 2.0f* 3.141f;
 float angleBetweenObjects = fullCircle/amountOfObjects;
 
 for(int i=0;i< amountOfObjects;i++)
 {
        ListOfYourObjects[i]._angle = i* angleBetweenObjects;
 }

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 alexjolig · Apr 25, 2018 at 08:30 AM 0
Share

It dosn't make a queue, some object will cover others this way.

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

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

Related Questions

Place object on radius pointing to a other object 1 Answer

Recalculate linerenderer when moving gameobjects 1 Answer

Can't get ship rotating in place to "launch" in direction it's currently facing 1 Answer

Rotate overtime to match waypoint 1 Answer

Firing a shell from a tank which rotates 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