Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 FXBaconGames · Aug 29, 2014 at 05:49 PM · rotationjavascriptcharactercontroller

Getting full rotation while in the air

I have a script that lets the player rotate on the y axis while it is in the air. I am trying to get the total amount of rotation while in the air. It seems that once the global rotation of the object exceeds 360 degrees, it resets back to 0, so I get inaccurate results. The player has a character controller if that somehow matters. Here is my code:

Move:

transform.Rotate(0,turnit, 0);

Get rotation:

 var controller : CharacterController = GetComponent(CharacterController);
 /////////////// 360 /////////////////
     if (controller.isGrounded == false) {
         if (canStartChecking == true) {
             three_sixty();
             
         }
     }
     
     if (controller.isGrounded) {
         if (canStartChecking == false) {
             canStartChecking = true;
             rotY2 = transform.rotation.eulerAngles.y;
             fullRot = Mathf.Abs(rotY2 - rotY);
             //Debug.Log(fullRot);
             
             if (fullRot > 160 && fullRot < 200) {
                 Debug.Log("180!");
             }
             
             if (fullRot > 340 && fullRot < 380) {
                 Debug.Log("360!");
             }
             
         }
     }
 //////////////// END OF 360 ////////////////
 }
 
 function three_sixty () {
     canStartChecking = false;
     rotY = transform.rotation.eulerAngles.y;
     var controller : CharacterController = GetComponent(CharacterController);
     
 }


I realize some of this is probably bad code, but its not final. Thanks in advance!

Comment
Add comment · Show 1
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 Scribe · Aug 29, 2014 at 07:23 PM 0
Share

$$anonymous$$aybe you could get the delta rotation that your object rotates by each frame and add those deltas up (or add up their absolute value) to get the amount you have rotated in the air. Alternatively you could set some tolerance point, which if reached you add 1 to a 'rotations' variable and then start counting again for the next full rotation

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FlaSh-G · Aug 29, 2014 at 09:45 PM

Simply don't read the object's rotation. Whenever you rotate:

 transform.Rotate(0, angles, 0);
 angleCounter += angles;

Then read angleCounter (which should be an instance variable of type float).

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

24 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

Related Questions

Rotate character to the moving direction problems? 2 Answers

Character Controller - Get Rotation from Ground 2 Answers

CharacterController doesn't rotate on my script... 1 Answer

Slerp Problem?: Enemy in Constant Rotation! 1 Answer

Camera lock on enemy 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