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 bali33 · Apr 22, 2014 at 10:49 AM · rotationquaternion

[Trackball] Rotation around 2 axis

Hi,

I'm trying to simulate a trackball by allowing a sphere to rotate around the x and y axis. I did a small piece of code to make my sphere rotate along those 2 axis simultaneously :

 void Update () 
         
     {   
         prevAngle.x += 5;
         prevAngle.y += 5;
 
         transform.eulerAngles = new Vector3(prevAngle.x%360,prevAngle.y%360,0);
 }

I was expected my sphere to rotate in "diagonal" but it is not the case - the movement is very weird.

I modified a bit the previous code in order to rotate only along the x axis and I was surprised to notice via the inspector that the x rotation value is not the only one to be update, sometimes the y and z values jump to 180 and then back to 0.

I do want the x and y rotation values to be the only one to be modified and I want to be able to compare between two updates the delta angle for the x and y axis.

I tried to use the Quaternion classes with the eulerAngles but I got a new problem, the x value freeze at 90 - cannot understand why.

So how can I make my sphere rotate along the X and Y axis and be able to calculate the delta angle for each axis ?

Thank you

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 jamesflowerdew · Apr 22, 2014 at 11:18 AM 0
Share

I think you need to move to relative rotations. Euler Rotations hard set like that won't give you what you want, (I'm imagining it looks a bit like a figure of 8 or a spiral, as you're effectively changing the axis with one and rotating with the other like seasons on earth).

 transform.rotation=Quaternion.identity;
 transform.rotate(new Vector3(prevAngle.x,pRevAngle.y,0),Space.World); 

will give probably smooth rotations although the axes may be wrong(I suspect x and z). You may need to reposition your sphere afterwards (?). alternatively, it may be easier to use a use $$anonymous$$athf.Sin and $$anonymous$$athf.cos to calculate a position around the sphere which it then looks at (transform.LookAt(wherever,Vector3.up)).

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by maddFrogg · Apr 22, 2014 at 10:59 AM

Have you tried this?

http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

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
0

Answer by bali33 · Apr 22, 2014 at 11:09 AM

Yes I did. The problem is the same, when you Rotate only along the x axis the y and z angle values are set to 180 for a short times. It seems that this modification occur when the x angle is equal to 360.

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 maddFrogg · Apr 22, 2014 at 11:18 AM 0
Share
 this.transform.Rotate( .5f, .5f, 0 );

This code rotates my sphere quite good, I don't know hat happens to yours. Please explain the weird movement you are experiencing.

avatar image bali33 · Apr 22, 2014 at 11:33 AM 0
Share

If I do this.transform.Rotate( .5f, .5f, 0 ) and then Debug the eulerAngle.x I can see that the value goes from 0 to 45. then to 0 then right after 0 the value change to 360 and then decreases etc. The x angle values update is weird, it's not like the value goes to 0 to 359 and then to 0 etc.

So it's not possible to compute and delta angle between two updates because sometimes you obtain strange values. I don't only want my trackball to rotate, I want to be able to know at each frame the angle delta for each axis in order to use those values to compute my main character speed for each axis.

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

22 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

Related Questions

Calculating Torque but cant add Quaternion 0 Answers

Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers

player rotation to follow the mouse 2 Answers

2D animation : problem with rotation interpolation 1 Answer

Clamped Turret Doesn't Want to Lerp the Other Way 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