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
1
Question by Josh707 · Aug 19, 2012 at 05:54 PM · rotationquaternionaxisslerp

Rotate object on one axis with slerp

I am trying to make my player model rotate with the camera orbit script, but only on the Y axis. So far I can have it rotate on every axis for the camera. This is what I've tried:

 var Player : Transform;
 var playerRotateSpeed = 2.0;

 function Update () {
     rot = transform.rotation; //rotation of the camera
     Player.transform.rotation = Quaternion.Slerp(Player.transform.rotation, rot, playerRotateSpeed);
 
 }



If I try (Player.transform.rotation.y, rot, playerRotateSpeed) it gives me an error saying slerp can only use (Quaternion, Quaternion, Float) and I'm giving it (Float, Quaternion, Float). Same if I try rot.y or anything else.

How can I get the rotation of one axis of my camera and Player in Quaternion form?

Using JS. This is probably really simple - I apologize as I only know C# and this mouse orbit script was in JS.

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
Best Answer

Answer by aldonaletto · Aug 19, 2012 at 07:34 PM

No, that's not so simple: you could use transform.eulerAngles.y to know the rotation around Y, but if the other X and Z components aren't zero, weird values may be returned. A more reliable alternative is to isolate only the horizontal camera direction and Slerp to it:

var Player : Transform; var playerRotateSpeed = 2.0;

function Update () { var dir = transform.forward; // get camera forward vector... dir.y = 0; // but keep only the horizontal direction var rot = Quaternion.LookRotation(dir); // now get the desired rotation Player.transform.rotation = Quaternion.Slerp(Player.transform.rotation, rot, playerRotateSpeed * Time.deltaTime); } Notice that I've multiplied playerRotateSpeed by Time.deltaTime in order to get frame rate independence.

Comment
Add comment · Show 1 · 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 Josh707 · Aug 19, 2012 at 09:12 PM 0
Share

Thank you. That is more complicated then I thought. I wasn't sure to multiply the speed by time either so thanks for that as well!

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Lookat via Single Axis 0 Answers

Quaternion.Slerp on local axis 1 Answer

Rotation of an object with quaternion 1 Answer

Choppy rotation of character around y-axis 1 Answer

i want to get my to cube to rotate 90 degrees on the x-axis as it jumps 0 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