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 sr388 · Oct 12, 2014 at 02:29 PM · rotationquaternionslerp

Rotation of an object with quaternion

I have a problem rotating an object with quaternion, when I rotate the object I use the function slerp to rotate from one rotation to another, but in this process the object loses its local Y axis rotation, so I want to know how could this be avoided, the code that I use:

 var orgRot = transform.rotation;     
 var myForward = Vector3.Cross(transform.right, normal);
 var dstRot = Quaternion.LookRotation(myForward, normal);
 for (var t: float = 0.0; t < 1.0; ){
     t += Time.deltaTime*2;
     transform.rotation = Quaternion.Slerp(orgRot, dstRot, t);
     yield; 
 }
Comment
Add comment · Show 5
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 robertbu · Oct 12, 2014 at 03:55 PM 0
Share

There are a number of techniques for solving this kind of problem, but in order to suggest one, I'd need a firm understanding of 1) what rotation you are looking for, and 2) a better idea of how this code is failing you. Images are good. Video can be helpful.

avatar image sr388 · Oct 17, 2014 at 06:19 PM 0
Share

$$anonymous$$y fault for not be more specified: the rotation that I am looking for it is the rotation of the player from the ground to a wall, the floor, an inclined surface, etc..., so this code is the part that calculates the rotation that has to be applied to the character from the previous rotation to the new rotation in the surface, which will be its new "ground" surface.

The problem: when the character is already in the new surface, he is not looking at the same angle in its y local axis that before, and I think that the problem has to be in this part of the code. Here some pictures:

Here is the character and behind him the wall which will become its new ground:

http://answers.unity3d.com/storage/attachments/33845-1.png

Now the character is floating, so the player can choose the surface to move the character, who is looking to the left in the picture:

http://answers.unity3d.com/storage/attachments/33847-2.png

2.png (65.5 kB)
1.png (101.3 kB)
avatar image sr388 · Oct 17, 2014 at 06:21 PM 0
Share

And finally the character in the new surface, and now the character is looking forward, when actually he should be looking to the left ( which is forward in the third picture)

http://answers.unity3d.com/storage/temp/33848-3.png

$$anonymous$$aybe the explanation is not clear, if it is the case, I will upload a video to youtube

3.png (117.5 kB)
avatar image robertbu · Oct 17, 2014 at 07:32 PM 0
Share

If I can getting a really clear idea of the rotation needed, I can almost always figure out the code. Here I'm still guessing. $$anonymous$$aybe you are looking for this:

    var dstRot = Quaternion.FromToRotation(transform.up, normal) * transform.rotation;
  
avatar image sr388 · Oct 17, 2014 at 08:21 PM 0
Share

That is exactly what I needed, now the character rotates from one surface to another correctly, and he makes a more natural movement, it is just I didn't undertand all the quaternion functions , thank you very much for the help robertbu

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by unimechanic · Oct 14, 2014 at 03:06 PM

I use the function slerp to rotate from one rotation to another, but in this process the object loses its local Y axis rotation

You can try rotating only in the axis that you need, check out this answer:

http://answers.unity3d.com/questions/246168/using-quaternionlookrotation-on-y-axis-only-but-ke.html

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 sr388 · Oct 17, 2014 at 06:30 PM 0
Share

The game is like gravity rush, so you can walk in any surface by changing the gravity of the player (not literally the physics.gravity, but similar), I think that I can't rotate only in one axis, because sometimes, the rotations are in the 3 axis at the same time, because these rotations are made taking in acount the rotation of the new surface that will become the new ground of the player.

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

LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 2 Answers

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

Rotation direction in coroutine 2 Answers

Quaternion slerp t parameter never reaches 1 1 Answer

Selecting the rotation direction for Quaternion.Slerp 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