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
2
Question by Karsnen_2 · Aug 29, 2012 at 02:22 PM · rotationgameobjectiosglobal

How to rotate an object around the world axis but not on the local axis?

Hello Devs,

I have a game object for which I am not sure of it's X or Z angle during run time. The game object is highly altered during runtime and the angles across X,Y and Z would be changing. But when the user gives the Input, it's angles are directly influenced only by the Input given by the user. At any point, the user might give an input as a target angle and I would like the game object to rotate from it's rotation to the desired target angles. The INPUT is basically only for X and Z and never Y. But while performing this I would like the angle on Y axis never to be affected. I would like to have the rotation on WORLD and not LOCAL.

Restrictions :

  1. Target Angle based upon the user INPUT.

  2. GLOBAL rotation

  3. Angle across Y axis should not be affected.

I have hitting across this for a long time, taking breaks in between. Can someone help me out to sort this?

THANK YOU.

regards,

Karsnen

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 Kryptos · Aug 29, 2012 at 02:58 PM 0
Share

The question is: what do you want to achieve? Please provide screenshots or diagrams of what you mean.

What do you mean by user input? How does the user provide this input.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kryptos · Aug 29, 2012 at 02:36 PM

Hints: the Transform class offers two different variables: rotation and localRotation. The first one is the world rotation, the second is the local rotation.


edit: I understand your mistake. Do you know that a Quaternion has 4 elements and that those elements have nothing to do with the xyz axis?

If you want to retrieve the angle around x, y or z-axis, use transform.eulerAngles. But I would recommend to never deal with euler angles. Instead, you can deal with direction.

Comment
Add comment · Show 12 · 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 Karsnen_2 · Aug 29, 2012 at 02:43 PM 0
Share

Yeah I have been using transform.rotation = Quaternion. The below code is what I have been using.

 //START
     anglcal();
                 targetRotation = Quaternion.Euler(reqAngle.x, this.transform.rotation.y, reqAngle.z); 
                 transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime*100f);
 //EOF

If you happen to look into this code, Y angle remains the same but there is no Global rotation.

$$anonymous$$ryptos - Do you see a mistake in my code?

avatar image Kryptos · Aug 29, 2012 at 02:57 PM 0
Share

What do you mean by there is no Global rotation?

You should consider using direction ins$$anonymous$$d of angle, along with Quaternion.FromToRotation.

avatar image Karsnen_2 · Aug 29, 2012 at 03:06 PM 0
Share

http://postimage.org/image/5m4iw8vv5/

If you happen look at the image about. At certain point the object suffers Y rotation but then when I apply the above code - the GameObject rotates locally. The above image has suffered a local X axis rotation but it had to be global X axis.

avatar image Kryptos · Aug 29, 2012 at 03:09 PM 0
Share

Sorry but with only one image, how am I supposed to understand what's going on?

avatar image Karsnen_2 · Aug 29, 2012 at 03:17 PM 0
Share

I have set of screenshots. I hope it helps to clear what I am trying to say.

  1. Normal position - When there is eulerangles are zero across X, Y and Z http://postimage.org/image/f1b46v7k1/

  2. When the game object suffers rotation across Y axis. http://postimage.org/image/nojq74w01/

  3. Expected GLOBAL rotation http://postimage.org/image/dsin7hq81/

  4. How it actually rotates - LOCAL http://postimage.org/image/8js7ncx6p/

Thank you.

Show more comments
avatar image
0

Answer by Tryz · Feb 07, 2015 at 04:09 PM

If you want to just use quaternions, you can do this:

 Vector3 lSpeed = new Vector3(0f, 90f * Time.deltaTime, 0f);
 Quaternion lCurrent = gameObject.Transform.rotation;
 Quaternion lNew = lCurrent * Quaternion.Euler(Quaternion.Inverse(lCurrent) * lSpeed);

In the last line, it counteracts the current rotation. So, when we add the speed to the current rotation, it results in a rotation around the world axes.

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

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

10 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to tilt the gameobject based of Input.Acceleration? 0 Answers

Using the accelerometer to rotate Camera 1 Answer

How to change child's rotation whithout affecting it's scale? 1 Answer

How to create a damped harmonic oscillation? 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