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 DeadKenny · Nov 24, 2013 at 03:36 PM · rotationinputvector3quaterniondirection

Quaternion amount/value of rotation?

Ok so I need to know how I can make this object(player controlled turret)which rotates on the Y axis to remember or get the value of the amount of a rotation that is happening, during a certain time.

What it does is rotates to a certain direction when a certain bool is true, which not using the input, as in you don't control it while this bool is true and while its rotating to this specific direction. So what I need is that specific amount of rotation that has happened on the axis while it rotates to said direction on its own.

Let me explain in code:

     Quaternion XQuaternion;
     
 //This is when the bool is not on and you are controlling the rotation with the Input of mouse.
     if(rTt != true){
     
        turretRotationX += Input.GetAxis("MouseX") * 1.6f * Time.deltaTime;
     
     }
     
    // So I want to do the same thing as above but not with the input but the amount the turret has rotated since the bool rTt has been true.
     
     if(rTt == true){
     
     //  turretRotationX += ??? AngleAxis? I don't how?
     
     
     
     }
     
    
     
 // This is where the mouse input goes into the rotation. // XQuaternion is what I want to change into the amount of rotation that has happened during rTt == true.

     turretRotationX = ClampAngle(turretRotationX, turretMinX, turretMaxX);

     XQuaternion =  Quaternion.AngleAxis(turretRotationX, Vector3.forward);
     
     //rot is the original rotation of the turret set in Start. Shouldn't be an issue here. 
     
     tur.localRotation = rot * XQuaternion; 
     
     

So yeah, please help.

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 robertbu · Nov 24, 2013 at 04:03 PM 1
Share

It is hard to understand what you are asking. $$anonymous$$aybe this post will help you:

http://answers.unity3d.com/questions/26783/how-to-get-the-signed-angle-between-two-quaternion.html

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DeadKenny · Nov 25, 2013 at 03:32 AM

Well you guys did help me a little in understanding my problem a little better, but I managed to avoid the whole thing by deleting it and replacing with:

     turretRotationX += Input.GetAxis("MouseX") * 1.6f * Time.deltaTime;
 
     transform.Rotate(turretRotationX , 0, 0);


This rotates without snapping.

However I don't know how to limit the angle when using transform.Rotate, because I need it for the barrel. Its fine like this for the turret though.

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
1

Answer by littlepsycho · Nov 24, 2013 at 04:41 PM

As far as I understand your question you want to modify the rotation of a GameObject.

Rotations are "stored" in Quaternions

Quaternions, Quaternion.Euler

 var rotation = Quaternion.Euler(10, 20, 30); // x:10, y:20, z:30

You can access the rotation on certain angels by

 Debug.Log(rotation.x) //Prints the x rotation -> 10



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 robertbu · Nov 24, 2013 at 05:00 PM 1
Share

@littlepsycho - The Debug.Log() will not work. The rotation you produce is a Quaternion, which is a non-intuitive, 4D construct. The values of x,y,z,w will have values between 0.0 and 1.0. You can something like:

 Debug.Log(rotation.eulerAngles.x);

...but you are not guaranteed to get 10 back out. eulerAngles are derived from the Quaternion, and the eulerAngle representation can change.

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

17 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

Related Questions

Rotate vector3 relative to another vector3 1 Answer

Get rotation from a vector direction. 1 Answer

3D nested Turret Prefab Rotation 1 Answer

Rotating a direction Vector3 by Quaternion 2 Answers

Rotate object based on hit normal + matching camera direction 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