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 /
  • Help Room /
avatar image
0
Question by Laniemme · Aug 22, 2016 at 07:30 PM · assetcirclerotating360-degrees

How Do I Rotate An Image Equally Around A Circle?

Hi, I have a player image that rotates around a central point. That part of the code works fantastic. If I had a sphere that had to rotate then life would be grand (so positioning is not an issue).

I have a bird that I need to rotate around the 'circle' and I'm not sure how to rotate it equally every frame so that after a complete circle the animation will start again.

The code below is what I use for positioning, however after a while you can see the image start turning into the center, like it is turning the image more than it should, so left long enough the image would be turning on itself:

     float circleDiameter = 4.0f;
     float timeCounter = 0;

     timeCounter += Time.deltaTime;

     float x = Mathf.Cos (timeCounter) * circleDiameter;
     float y = Mathf.Sin (timeCounter) * circleDiameter;
     float z = 0;
     float GullRotatedValue = 360;
     float rotationIncrement = 1;
     transform.position = new Vector3 (x, y, z);

The first revolution looks ok, but then the bird starts rotating more than it should and starts pointing towards the center of the circle instead of continuing to fly around it. Here is the code for rotating:

     if (GullRotatedValue < 0) {
         GullRotatedValue = 359f;
     } else {
         GullRotatedValue = GullRotatedValue - rotationIncrement;
     }

     PlayerGull.transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, GullRotatedValue);

This is the first app I have worked on and am far from proficient in Unity, so any pointers would be welcomed. I did look for other existing answers, but couldn't find a good fit for my question.

If the code needs a correction, or if there is a better way to achieve this then I am happy to learn.

Thanks.

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 Graphics_Dev · Aug 22, 2016 at 08:09 PM 0
Share

Why can't this be done with animations?

avatar image Laniemme Graphics_Dev · Aug 22, 2016 at 09:08 PM 0
Share

How would you handle it with animations? Eventually the bird will be flapping but it's the rotation of the asset that is causing the issue.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jessespike · Aug 22, 2016 at 08:28 PM

Can't test partial code, but looking over it. This sections doesn't look right:

  if (GullRotatedValue < 0) {
      GullRotatedValue = 359f;
  } else {
      GullRotatedValue = GullRotatedValue - rotationIncrement;
  }

the value is getting set to 359 when it's below 0, but what happens if the value was -5 before the if-statement? Shouldn't the next value be something like 354 instead of 359?

Basically, take in account the remainder value when resetting. Maybe this will work:

 GullRotatedValue -= rotationIncrement;
 if (GullRotatedValue < 0f) {
     GullRotatedValue += 360f;
 }

An even simpler way is to parent the bird to a GameObject and rotate the parent.

 public class RotateTest : MonoBehaviour {
 
     public float speed = 10f;
 
     // Update is called once per frame
     void Update () {
         transform.Rotate(Vector3.forward * Time.deltaTime * speed);
     }
 }

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 Laniemme · Aug 22, 2016 at 09:07 PM 0
Share

Thanks for your reply. I created a test rotate script with your code to a parent of the object and it made a huge arc that went way outside the normal boundaries. Not sure what was going on there.

I updated the GullRotatedValue code with your suggestion and the situation seems to be unchanged.

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

64 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

Related Questions

Jump perpendicular/adjacent to current point on a rotating circle 0 Answers

when Application.LoadLevel(''sceneName'),if sceneName is a small scene,no problem,but when scene is a large scene,that produce a problem that ArgumentException: GetLocalizedString can only be called from the main thread. 1 Answer

Can't find tutorial Assets in Asset store 1 Answer

Unity instantly deletes Asset folder which I pull over Git - "Removing Assets/FolderName because the asset does not exists" 0 Answers

Is there a quick and dirty way to get a list/array of user MonoScripts in a project? 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