• 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 martinstian · May 31 at 07:11 PM · programming

how to find way of rotation

how do i track the way the character rotates. and what speed it rotates in. like i wanna track if it goes up down left or right,how do i track my rotation so that it knows what way it goes. i tried but i couldnt do it without anything else then the position value

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
1

Answer by Quatnu · May 31 at 08:41 PM

I don't know your code or if your game is 3D or 2D but to find the direction it could be just:

      if (transform.eulerAngles.z == 0) //Up (or you can setup bounds for the rotation – example: if (transform.eulerAngles.z > 350 && transform.eulerAngles.z < 10))
     {

     }

     if (transform.eulerAngles.z == 90) //Right – example: if (transform.eulerAngles.z > 80 && transform.eulerAngles.z < 100))
     {

     }

     if (transform.eulerAngles.z == 180) //Down
     {

     }

     if (transform.eulerAngles.z == 270) //left
     {

     }

For determining the rotation speed, you can try this in void Update():

 rotationSpeed = transform.eulerAngles.z - previousRotation;
 previousRotation = transform.eulerAngles.z;

And this in void Start():

 previousRotation = transform.eulerAngles.z;
Comment
Add comment · Show 2 · 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 martinstian · Jun 01 at 04:15 PM 0
Share

but how could this work on others than the standard rotation

avatar image Quatnu martinstian · Jun 01 at 07:24 PM 0
Share

what do you mean?

avatar image
1

Answer by lexar1232015 · May 31 at 08:37 PM

Try creating a coroutine with a delay yield return new WaitForFixedUpdate(); and make it self-invoking. Each call write the value of transform.Rotation to a local variable and check what it was before. So you can calculate the speed and direction

Comment
Add comment · Show 4 · 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 martinstian · Jun 01 at 12:15 PM 0
Share

ok i am gonna try now

avatar image martinstian · Jun 01 at 04:08 PM 0
Share

but i have a question how do i save them in the right way i tried but i couldnt manage

avatar image lexar1232015 martinstian · Jun 01 at 04:38 PM 0
Share

Quaternion _lastRotation = transform.rotation;

avatar image martinstian lexar1232015 · 3 days ago 0
Share

do you now how i can check for what the value was a little while ago after a button press

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

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

Multiple Cars not working 1 Answer

Socket programming in unity 3 Answers

Multiple GUI.Labels to appear and disappear 1 Answer

C# GameObject Lists 2 Answers

Getting interactive grass texture or getting grass onto a plane instead of terrain. 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