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 /
avatar image
1
Question by operand · Sep 24, 2011 at 07:35 AM · rotationquaternionaxisspace

Problem with quaternion rotation zxis

Hello, I have the following script attached to a cube which allows it to be moved upwards. It translates and rotates according to left and right keyboard input, the only problem is that it rotates in world space, not it's local space. How can I change this to make it rotate according to its own z-axis, not the worlds?

 var momentum : float = 3;
 //smooth : the lower the slower
 var smooth;
 
 function Update () {
 
 var tiltAngle = -60.0;
 var horiz = Input.GetAxis("Horizontal");
 var target = Quaternion.Euler (0, 0, horiz*tiltAngle);
 var zeroed = Quaternion.Euler (0, 0, 0);
 
 
 //Increases forward momentum over time
 momentum += Time.deltaTime*0.25;
 
 //Left + right Translation and Upward Momentum
 transform.Translate(horiz*0.25,Time.deltaTime*momentum, 0, Space.Self);
 
 
 if (Input.GetButton("Horizontal")){
 // Dampen towards the target rotation
 smooth = 7.5;
 transform.localRotation = Quaternion.Slerp(transform.localRotation, target,Time.deltaTime * smooth);
 }
 
 
 if(Input.anyKey == false){
 smooth = 2;
 transform.localRotation = Quaternion.Slerp(transform.localRotation, zeroed,Time.deltaTime * smooth);
 }
 
 }


I'd appreciate any help you can give me with this, I'm really stumped by it.

Thanks

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 SilverTabby · Sep 24, 2011 at 07:38 AM 0
Share

The reason it's not rotating along it's own axis is because localRoatation isn't the world space of this transform, it is the world space of it's parent's transform.

That's why It's not working, but I'm blanking on how to make it work as advertised (why this isn't an answer). I think I need more sleep.

avatar image operand · Sep 24, 2011 at 07:48 AM 0
Share

Hrrm I see but this has no parent, it's just a cube object with the script on it. This is driving me craaaazy. Thanks for the quick reply though, go have a snooze!

avatar image operand · Sep 24, 2011 at 08:46 AM 0
Share

With some help off 'deram_scholzara' on the 'Unity Community' the problem seems to be resolved by changing :

var target = Quaternion.Euler (0, 0, horiz*tiltAngle);

to:

var target = Quaternion.AngleAxis (horiz*tiltAngle, transform.forward);

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rotating on a plane 2 Answers

Rotating multiple points in space. 0 Answers

Apply a Rotation in World Space based on Quaternions 2 Answers

[Please!] Noob need's help with planet gravity movement. 2 Answers

how can i substract one axis by 180? 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