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 Daniel G · Jan 08, 2014 at 09:51 PM · rotationvector3euleranglesunderstand

Add a Vector3 to the rotation of an obj and have it behave with logic!

Hello, I am adding vector3 to the rotation of an obj (I think .rotation is in eurler angles). And any time the y axis gets out of place I CANT rotate the obj in any logical form! For instance I'll add 90° to the x-axis with the why is pointing away from me and it will add 90 to the right axis BUT IT TURNS around some other axis...

Basically I'm wondering how to add vector3 to the rotation of the object, and get logical results (Im rotating in LOCAL space).

The process I am using: Grabbing the objects original rotation, before rotating. Creating a new vector3 by adding the original rotation to a New vector3 with the 90° increment on the respective axis. Then I am rotating object by that new vector3 I am directly changing the rotation of the object to that new vector3 over, time.time- starttime/(Number of secs)

I even know what face is facing the player, and I know where the y-axis is pointing in space. By knowing that I can choose over which axis to rotate.

Code: (I apologize for the MASS of code) NOTE: gObjectBuilder is the GameObject im trying to rotate...

 if (CanRotateBuilderObj) {
                         gObjectBuilderOriginalRotation = gObjectBuilder.transform.rotation.eulerAngles;
                     }
 
 //I have rotate back right and left as well, this is just one set (Fwd)
 if (RotateFwd && CanRotateBuilderObj) {
                         if (gObjectBuilderBackFaceIsFacingPlayer) {
                             if (gObjectBuilderPositiveYAxisIsFacingUp) {
                                 StartCoroutine(gObjectBuilderRotateCoroutine());
                                 gObjectBuilderNewRotation = gObjectBuilderOriginalRotation + new Vector3(90f,0,0);
                                 CanRotateBuilderObj = false;
                             }
                             if (gObjectBuilderPositiveYAxisIsFacingDown) {
                                 StartCoroutine(gObjectBuilderRotateCoroutine());
                                 gObjectBuilderNewRotation = gObjectBuilderOriginalRotation + new Vector3(-90f,0,0);
                                 CanRotateBuilderObj = false;
                             }
                             if (gObjectBuilderPositiveYAxisIsFacingRight) {
                                 StartCoroutine(gObjectBuilderRotateCoroutine());
                                 gObjectBuilderNewRotation = gObjectBuilderOriginalRotation + new Vector3(0,-90f,0); //Double CHECK could be +90f :P
                                 CanRotateBuilderObj = false;
                             }
                             if (gObjectBuilderPositiveYAxisIsFacingLeft) {
                                 StartCoroutine(gObjectBuilderRotateCoroutine());
                                 gObjectBuilderNewRotation = gObjectBuilderOriginalRotation + new Vector3(0,90f,0); //Double CHECK could be -90f :P
                                 CanRotateBuilderObj = false;
                             }
                         }
 
 
 //That coroutine that is being started
     IEnumerator gObjectBuilderRotateCoroutine() {
         gObjectBuilder.rigidbody.freezeRotation = false;
         while ((Time.time - RotatingStartTime) <= 0.5f) {
             gObjectBuilder.transform.eulerAngles = Vector3.Lerp(gObjectBuilderOriginalRotation, gObjectBuilderNewRotation, (Time.time - RotatingStartTime)/0.5f);
             yield return null;
         }
         gObjectBuilder.rigidbody.freezeRotation = true;
         CanRotateBuilderObj = true; 
     }



THANKS, Daniel

Comment
Add comment · Show 3
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 Daniel G · Jan 08, 2014 at 09:53 PM 0
Share

Im am writing in C# for the reference

avatar image Daniel G · Jan 08, 2014 at 10:08 PM 0
Share

@aldonaletto I Noticed you helped some one else out with a similar issue, any ideas? Im wanting to stick with using vector3's not just adding a float to one of the vecotor3's axises.

Here was that someone else: http://answers.unity3d.com/questions/234007/rotate-object-over-time-90-degrees-at-a-time.html

Ive learned that you DO NOT want to be messing with quanternions so im using eurlerangles

avatar image Daniel G · Jan 09, 2014 at 06:55 PM 0
Share

@robertbu I noticed you help some one with this very thing here http://answers.unity3d.com/questions/462073/how-to-use-euler-angles-to-rotate-an-object-.html

Trouble is I need to read those eulerAngles to take a snapshot in time of the transforms rotation before rotating... How can I accomplish this?? I read that whole answer you gave to that guy and i noticed you said to NEVER read the eulerAngles... I dont know how to do what I want without it? any $$anonymous$$gestions? Thanks for your time!

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

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

Multiple Cars not working 1 Answer

Object wont rotate in the opposite direction 1 Answer

How is the rotation of a Transform converted into a Vector3 in the inspector ? 2 Answers

Lerping euler angles make entire spin 3 Answers

How do I make create a rotateable object that follows a raycast hit point? 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