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 DiXa · Mar 23, 2015 at 03:00 PM · rotationquaternionaxislocalslerp

Quaternion.Slerp on local axis

I have a Playercontroller gameobject which is looking at the center of the game world with LookAt function. That Playercontroller has a child object which has the graphics on it and I would like to rotate that child gameobject in its local axis(for example when A is pressed it rotates it to the left and when D is pressed then to the right)

This is what i use for now in the child gameobject for WASD input:

     if (Input.GetKey ("a")) {
             transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.AngleAxis(-90, Vector3.up), Time.deltaTime * rotationSpeed);
         }

It works at the beginning because the playercontroller has 0, 0, 0 rotations, but obviously the child object doesnt rotate correctly when i start to move. I have tried transform.localRotation but it gets really weird results(continuously rotation, does not stop at wanted Y axis degrees).

Any help or guidance would be greatly appreciated

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
3

Answer by Baste · Mar 23, 2015 at 04:53 PM

If you want to rotate your current rotation a certain number of degrees, you multiply the rotation you want "added" with your current rotation. It's weird, I know, but Quaternions are Quaternions.

So I'm pretty sure this would work:

 if(Input.GetKey ("a")) {
     Vector3 currentRotation = transform.rotation;
     Vector3 wantedRotation = currentRotation * Quaternion.AngleAxis(-90, Vector3.up);
     transform.rotation = Quaternion.Slerp(currentRotation, wantedRotation, Time.deltaTime * rotationSpeed);
 }

This means that you will, when holding down a, Slerp towards a rotation that's 90 degrees counterclockwise from your current rotation. This should give a constant rotation speed.

Hope that helps!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Lookat via Single Axis 0 Answers

Rotate object on one axis with slerp 1 Answer

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

Finding the Euler angles of an object's rotation in terms of a different set of axes 0 Answers

LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 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