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 nric2001 · Feb 20, 2019 at 04:14 PM · rotationcoroutineienumerator

calculating player rotation direction

so, I've been trying to calculate the rotation direction of the player using coroutines and have run into some issues after doing some research... I'm new to using these, and know the issues are with improper setup of the code itself. what i'm hoping is you can see what I've done improperly...

thank you in advance!!

 public enum playerTrans { Left, Right, Idle }
 private bool continuePlayerRotationCalculation = false;
 
  void Start()
     {
         StartCoroutine(PlayerRotationCalculator(transform));
     }
 
   void DoStartPlayerRotationCalculation()
         {
             bool ContinuePlayerRotationCalculation = false;
 
         IEnumerator PlayerRotationCalculator(Transform transform.rotation);
         {
             yield return null;
 
             ContinuePlayerRotationCalculation = true;
 
             float oldYAngle = 0;
             float newYAngle = 0;
             bool isIdle = false;
 
             oldYAngle = Mathf.Abs(transform.rotation.eulerAngles.y);
 
             while (ContinuePlayerRotationCalculation == true)
             {
                 newYAngle = Mathf.Abs(transform.rotation.eulerAngles.y);
 
                 if (oldYAngle < newYAngle)
                 {
                     isIdle = false;
                     oldYAngle = newYAngle;
                     Debug.Log("Left");
 
                     anim.SetBool("isTurningLeft", true);
                     anim.SetBool("isTurningRight", false);
                 }
                 else if (oldYAngle > newYAngle)
                 {
                     isIdle = false;
                     oldYAngle = newYAngle;
                     Debug.Log("Right");
 
                     anim.SetBool("isTurningLeft", false);
                     anim.SetBool("isTurningRight", true);
                 }
                 else if (!isIdle)
                 {
                     isIdle = true;
                     oldYAngle = newYAngle;
                     Debug.Log("Idle");
                 }
 
                 yield return null;
             }
         }
     }
 
     void DoStopPlayerRotationCalculation()
     {
         continuePlayerRotationCalculation = false;
     }
Comment
Add comment · Show 4
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 RobAnthem · Feb 20, 2019 at 04:16 PM 0
Share

What in gods name made you decide to perform player rotation in a coroutine?

avatar image nric2001 RobAnthem · Feb 20, 2019 at 04:21 PM 0
Share

i'm not perfor$$anonymous$$g rotation in the coroutine itself. the only thing the coroutine is for is to calculate what direction the player is rotating.

i already have rotation in another part of my code. this isn't what makes the player rotate.

but that said, what would you reccomend to find current rotation? is there a simpler way or...?

avatar image RobAnthem nric2001 · Feb 20, 2019 at 04:41 PM 0
Share

I guess I'm just confused, wouldn't you know if the player was turning left or right in your controller script? Is it using a nav agent? Because you can still figure out turning direction from a nav agent by calling to the Nav$$anonymous$$eshAgent.angularSpeed field.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

140 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 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

How can you tell if a gameobject is looking directly at another gameobject? 1 Answer

WaitForSeconds Not Working 4 Answers

Shooting when raycast hits player with delay between shots, Coroutine not working as I intend 1 Answer

Need Help with a Null Reference 1 Answer

SpeedBoost won't reset : Problem with either WaitForSeconds or Coroutine (Solved) 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