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 /
  • Help Room /
avatar image
0
Question by correojon · Aug 22, 2015 at 07:09 PM · transformrotate

Applying two independent rotations

I´m doing a racing game where the player can perform tricks in the air. The tricks consist of local rotations around the transform´s x, y and z axis. For simpler tricks, the player will just do one complete rotation a single axis, but for more complicated tricks he may do more than one rotation around 2 or more axis at the same time. This is where my problem lies, for rotations around a single axis everything works fine, but when I try to rotate around 2 axis at the same time I get weird behaviours.

This is a code snipet that calculates the rotation in every axis:

    if (currentTrick > -1){
                 for (int i=0; i<3; i++){
                     if (currentTrickTurns[i] < trickTurns[i]){
                         if (trickTurnSpeed[i] > 0f){
                             if (trickRotation[i] + trickTurnSpeed[i] < 360f) trickRotation[i] += trickTurnSpeed[i];
                             else{
                                 trickRotation[i] = 0f;
                                 currentTrickTurns[i]++;
                             }
                         }else if (trickTurnSpeed[i] < 0f){
                             if (trickRotation[i] + trickTurnSpeed[i] > 0f) trickRotation[i] += trickTurnSpeed[i];
                             else{
                                 trickRotation[i] = 360f;
                                 currentTrickTurns[i]++;
                             }
                         }
                     }else{
                         trickTurnSpeed[i] = 0f;
                         trickFinished[i] = true;
                     }
                 }
             }
             if (trickFinished[0] && trickFinished[1] && trickFinished[2]) TrickEnd();

This calculates the current rotation in degrees in each angle and the number of turns, setting the speed to 0 when the trick is completed.

For applying the rotations I´ve tried many things with different results.

Using transform.Rotate:

 transform.Rotate(new Vector3(trickTurnSpeed[axisX], 0f, 0f));
 transform.Rotate(new Vector3(0f, trickTurnSpeed[axisY], 0f));
 transform.Rotate(new Vector3(0f, 0f, trickTurnSpeed[axisZ]));

The player rotates around all axis at the same time. That is, instead of turning around X, then Y and then Z, the resulting rotation is like the player rotated around Vector3(trickTurnSpeed[axisX], trickTurnSpeed[axisY], trickTurnSpeed[axisZ]).

Using quaternions:

 qTrickRotationX = Quaternion.AngleAxis(trickRotation[axisX], Vector3.right);//transform.right);
 qTrickRotationY = Quaternion.AngleAxis(trickRotation[axisY], Vector3.up);//transform.up);
 qTrickRotationZ = Quaternion.AngleAxis(trickRotation[axisZ], Vector3.forward);//transform.forward)
 transform.localRotation = qTrickRotationX*qTrickRotationY*qTrickRotationZ;

I get erratic turns this way.

Using eulerAngles:

 transform.eulerAngles = newRot + new Vector3(trickRotation[0], trickRotation[1], trickRotation[2]);

I get the same as using transform.Rotate.

Using transform.RotateAround:

 transform.RotateAround(transform.position, transform.right, trickTurnSpeed[axisX]);
 transform.RotateAround(transform.position, transform.up, trickTurnSpeed[axisY]);
 transform.RotateAround(transform.position, transform.forward, trickTurnSpeed[axisZ]);

Again, I get wrong rotations.

I´ve tried many more things, all with undesired results. Please help me, I´m running out of ideas :(

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

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

25 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

Related Questions

Rotate Camera in Y axis without visibly changing angle in Z axis 2 Answers

transform.rotation interferes with transform.Rotate 1 Answer

How do I move my 2d sprite left and right but also rotate in- place! 1 Answer

Rotating transform around axis specified by another object in world 1 Answer

How do I rotate a game object around a custom pivot? 1 Answer


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