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 masonb21 · Sep 19, 2016 at 06:22 PM · camerarotationchess

how to make the camera rotate each turn

I'm trying to make the camera rotate for each players turn in a chess game, but when I made this code, the camera would stop moving. Anyone know the solution.

 public void RotateCamera()
 {
     int x = 0;
     if (isWhiteTurn == true)
     {
         transform.Rotate(0, 0, 0);
     }
     else
     {
         while(x < 180)
         {
             transform.Rotate(0, x, 0);
             x++;
             if(x >= 180)
             {
                 break;
             }
         }
     }
 }

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 Sergio7888 · Sep 19, 2016 at 09:26 PM 0
Share

This code is execute where? Inside of a Update or inside a coroutine?

avatar image masonb21 Sergio7888 · Sep 19, 2016 at 10:45 PM 0
Share

I executed the code in Update

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tiggy02 · Sep 20, 2016 at 06:04 AM

Dear masonb21.

The problem is that since you executed this is Update and you set the value of x to 0 in the function every frame you set x to 0. The solution is to declare x in a Start or Awake function.

Hope this works, tiggy02.

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 OutOfRam · Sep 20, 2016 at 02:45 AM

The problem is that you are using a while loop rather than a coroutine. A while loop will run every iteration of itself in a single frame. In other words, if you have a while loop that runs 180 times, all 180 loops will be calculated and done in a single frame. a coroutine on the other hand can be made to run a single iteration once every frame, or what ever time interval you want. Try something like this (i don't have unity near me, so it may not be perfect)

 private IEnumorator Rotate()
 {
     int x = 0;
     if (isWhiteTurn == true)
     {
         transform.Rotate(0, 0, 0);
         yield return null;
     }
     else
     {
         while(x < 180)
         {
             transform.Rotate(0, x, 0);
             x++;
             yield return WaitForSeconds(AmountOfTimeBeforeNextLoop);
         }
     }
 }

you are going to want to start the coroutine using

  StartCoroutine("Rotate"); // Rather than Rotate()

I hope this helps

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 felipin · Sep 20, 2016 at 06:06 AM

Try the code below buddy

 public bool isWhiteTurn;
 public float rotationSpeed;
     
 public void RotateCamera ()
 {
     Quaternion targetRotation = Quaternion.Euler (0, isWhiteTurn ? 0 : 180, 0);
         
     transform.rotation = Quaternion.Lerp (transform.rotation, targetRotation,
                                             Time.deltaTime * rotationSpeed);
 }
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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to smoothly rotate camera around an object with touch 1 Answer

How to force camera rotation? 1 Answer

The solution with camera rotation which is used in most strategic games 1 Answer

Rotate camera 1 Answer

Rotating gameobject after mouselook 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