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 Karsnen_2 · Aug 01, 2012 at 07:30 PM · c#rotationiostransform

Help regarding World-Local Transfrom Rotation?

Hello,

I have an object in a Top-Down view. By which I mean to say that the object moves along X and Z axis. Due to it's motion at times, it experiences slight rotation along Y axis. Now the problem is when I try to tilt my iOS device, I would like the object to move along the direction I tilt and rotate at the same time. i.e. by X and Z axis.

CODE :

 //Implementing Rotation
     angx = Mathf.SmoothDampAngle(transform.rotation.eulerAngles.x, reqAngle.x, ref yVelocity, Time.deltaTime * 2f);
  angz = Mathf.SmoothDampAngle(transform.rotation.eulerAngles.z, reqAngle.z, ref yVelocity, Time.deltaTime * 2f);
  transform.rotation = Quaternion.Euler(angx, transform.rotation.eulerAngles.y, angz);
 
 // Getting the Input from the accelerometer and determining the angle
         {
  if(dir.x>0)
  reqAngle.z = -(dir.x * 100);
  if(dir.x<0)
  reqAngle.z =  -(dir.x * 100);
  }
  
 //END

EXPLANATION

I get the Input and depending upon the Input and calculate the angle to be rotated. Then the angle is used to calculate the Rotation. Now, the object by itself has a rotation along Y axis. Here I never intend to manually rotate the Y axis. The code I have used is transform.rotation and from the unity documentation it says it is a world rotation rather than a local rotation.

PROBLEM :

When I tilt my iOS device and at that particular instance if the object has experienced some Y degree rotation - to my input the object rotates locally.

I hope my explanation is clear and I am not sure where I have gone wrong, if so. Could someone help me with this.

Thank you and I highly appreciate your help...

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ScroodgeM · Aug 01, 2012 at 09:09 PM

it's bad practice to use euler angles to read data. you can got two different Euler Angles with same rotation. it's normal. so don't use it in this case. try something like:

Quaternion targetRotation = Quaternion.Euler(reqAngle.x, 0f, reqAngle.z); // insert some default Y rotation if needed
transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * 2f);
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 Karsnen_2 · Aug 02, 2012 at 02:08 PM 0
Share

Thanks Scroodge. I did implement it. $$anonymous$$y code goes like this.

 Quaternion targetRotation = Quaternion.Euler(reqAngle.x, transform.eulerAngles.y, reqAngle.z); 
  transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * 100f);

But yet again, it rotates along it's local and not world. I am not sure why and what is the issue? The notable changes I made from your reference is that I have kept Y angle to be the same & the speed is Time.deltaTime * 100f.

Is there a problem if I happen to pass transform.eulerAngles.y in Quaternion.Euler?

avatar image ScroodgeM · Aug 02, 2012 at 07:02 PM 0
Share

like i said already, be sure in what are you doing if you read euler angles and use it.

if you need just store initial eulerAngles.y and keep it, then store it in local variable once before any rotation and use it when rotating.

these lines will rotate an object always by it's Z and X axis

if you need rotation always in world space (like trackball), use Rotate method:

transform.Rotate(Vector3.forward, deltaZrotation, Space.World);
transform.Rotate(Vector3.right, deltaXrotation, Space.World);

say if you need explain

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

7 People are following this question.

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

Flip over an object (smooth transition) 3 Answers

How to create a damped harmonic oscillation? 1 Answer

[Solved] Help on a rotation issue for a Top-Down view? 1 Answer

C# Need Help Refining Ricochet Script 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