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
2
Question by FLASHDENMARK · Jun 08, 2011 at 09:01 PM · rotationquaternionsmooth

How to, restrict Quaternion.Slerp to the Y axis?

Hello fellow uniteres!

I have a third person game where the camera is free to rotate around when the player is not moving. And when the player is moving the players Y axis lines with the cameras Y axis, but when doing so the player "snaps" to the cameras Y axis.

I want to make this smooth and therefor considering using Quaternion.Slerp, but the problem using Quaternion.Slerp is that it is "Slerping" all axis X, Y, Z, but as said I only want to "Slerp" the Y axis. Is this possible(It most likely, but I do not know how to) I have tried Mathf.Clamp, but that causes "shaky" movements and slow fall through the floor.

The current code I use for the rotation right now is this(small sample only):

   var GameCam : Transform; //Camera goes here.
 
     if(Input.GetAxisRaw("Vertical") > 0.1 && !Input.GetAxisRaw("Horizontal"))
     {
     transform.eulerAngles.y = GameCam.eulerAngles.y; // This is used for the rotation
     transform.Translate(0,0,Input.GetAxisRaw("Vertical")/20);//Movement no need to look at that.
     }

So can you please tell me a way to restricting "Slerping" to the Y axis only. I will be greatfull!

Comment
Add comment · Show 2
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 Chris D · Jun 08, 2011 at 09:30 PM 0
Share

Can you post your current Slerp code?

avatar image FLASHDENMARK · Jun 08, 2011 at 09:52 PM 0
Share

I do not have any Slerp specific code since I could not for the life of me restrict it to the Y axis only so I sticked to the code in the updated post.

3 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by testure · Jun 08, 2011 at 09:57 PM

yourRotationQuaternion = Quaternion.Slerp(to, from, time);

yourRotationQuaternion = Quaternion.Euler(new Vector3(0f, yourRotationQuaternion.eulerAngles.y, 0f));

done like dinner

Comment
Add comment · Show 6 · 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 FLASHDENMARK · Jun 08, 2011 at 10:14 PM 0
Share

Thank you. tried messing with it, but importunately the player only turns/rotates 0.8 degrees each direction and nothing more and then the player is kinda "clamped" there and can not rotate further.

avatar image Peter G · Jun 09, 2011 at 01:50 AM 0
Share

You corrected Anxo, but you made the same mistake. yourRotationQuaternion.y is not an euler value so putting it into Quaternion.Euler is a mistake

avatar image testure · Jun 09, 2011 at 02:29 AM 0
Share

Ah- yes. I've edited my post to clarify.

Just more proof that we need intellisense here too :)

avatar image djzmaj123 · Jun 18, 2013 at 07:23 PM 0
Share

f yeah! Thanks for this!

avatar image rocket5tim · Jul 19, 2013 at 03:21 PM 0
Share

Works like a charm. Thanks! The original poster should mark this "answered".

Show more comments
avatar image
1

Answer by flim · Jun 09, 2011 at 05:21 AM

After the Quaternion.Slerp statment

transform.localEulerAngles = Vector3(0, transform.localEulerAngles.y, 0);

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 Symgy · Apr 23, 2017 at 02:48 PM 0
Share

THAN$$anonymous$$ YOU SOOO $$anonymous$$UCH :)

avatar image
0

Answer by Anxo · Jun 08, 2011 at 10:29 PM

transform.rotation.y = Quaternion.Slerp(bla bla bla).y;

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 testure · Jun 08, 2011 at 10:45 PM 0
Share

yeah, but Y is not what you're thinking it is- he's talking about restricting to the Y euler angle, this would give you the Y quaternion component, which is not the same thing:

http://unity3d.com/support/documentation/ScriptReference/Quaternion.html

avatar image Anxo · Jun 09, 2011 at 11:52 AM 0
Share

oh I guess I tried to answer the title without reading the question.

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

Quaternion, Smooth cube rotation using "wheel" 2 Answers

Quaternion snaps to a rotation when moving (and with input)? 1 Answer

Lerp with raycast hit.normal? 2 Answers

Smoothing the characters rotation with Lerp 2 Answers

How to ROTATE an object without slowing the ends (lerp) 3 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