Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 gopics · Sep 26, 2014 at 02:33 PM · rotationvector3quaternionangleconvert

how to convert the angle to roatation?

hai guys....am trying to move the vehicle based on the directional vectors...when am try to translate it works quite well but when try to rotate it doesnt perform well.....this is my concept....i have the two directional vectors using this i found the angle how much the vehicle want to rotates(using vector3.angle). using this angle how can i supposed to rotate??? i dont know how to convert the signedAngle value into the rotations....i just read somewhere using quaterinion we can rotate but i dont know...please give some practical explanation with the example code.....Thank u...

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

Answer by robertbu · Sep 26, 2014 at 02:39 PM

Vector3.Angle() does not help you since the result is unsigned. Given the forward vector of your vehicle and a vector indicating where you want it to point you can create a Quaternion:

 var q = Quaternion.FromTo(myForward, nextDirection);

...then you can set the rotation immediately by:

 transform.rotation = q * transform.rotation;

...or you can do it over time with easing by:

 transform.rotation = Quaternion.Slerp(transform.rotation, q * transform.rotation, Time.deltaTime * speed); 

For a vehicle, you sometimes want to force the angle of rotation. Assuming you've defined the front of your vehicle as the side facing positive 'z' when the rotation is (0,0,0), you can use Quaternion.LookRotation():

 var q = Quaterion.LookRotation(nextDirection, transform.up);

...and the Slerp would be:

 transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * speed);

Note for a non-eased rotation, Slerp() can be replace by RotateTowards(). 'speed' would then be measured in degrees per second and would have to be greatly increased from the value used in Slerp().

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 gopics · Sep 29, 2014 at 11:58 AM 0
Share

hai mr.robertu ......actually i have the signed ange between two directional vector....using that angle how can i achieve the rotation??? is there possible to rotate the car using angle???

avatar image robertbu · Sep 29, 2014 at 02:25 PM 0
Share

In addition to the signed angle, you need the axis. If you have the axis, you can do:

 transform.rotation = Quaternion.AngleAxis(angle, axis) * transform.rotation;

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

2 People are following this question.

avatar image avatar image

Related Questions

Rotate floor plane in-game via C# script 1 Answer

Make a side of an object LookAT another object 1 Answer

Set rotation based on 1,1,1 style vector? How to convert vector3 to quaternion? 1 Answer

combine / convert rotations (Quaternion and Vector3) 1 Answer

Rotate angle between two points 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