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
4
Question by Heke · Jun 17, 2013 at 05:18 PM · rotationquaterniontransparencytranslate

[SOLVED]How to change Quaternion by 180 degrees?

I'm trying to instantiate an object, a bullet, so it comes from the back of the object. In other words, Im trying to change its degrees by 180, but it's quaternion so it's more complicated. Anyway here's my code:

 Instantiate(bullet, transform.position, transform.rotation);
 //transform.rotation needs to be translated by 180 degrees

here's the final working code:

             var rot : Vector3 = transform.rotation.eulerAngles;
             rot = new Vector3(rot.x, rot.y, rot.z + 180);
             Instantiate(bullet, transform.position, Quaternion.Euler(rot));
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 Fattie · Jun 17, 2013 at 05:42 PM 0
Share

Never use quaternions, unless you are doing something very advanced.

Just use Euler angles, or simply .Rotate.

Also LookAt is very useful.

avatar image Heke · Jun 17, 2013 at 09:30 PM 0
Share

Yea but when using instantiate, you have to use quaternion

5 Replies

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

Answer by equalsequals · Jun 17, 2013 at 05:27 PM

You can use Quaternion.eulerAngles to get a Vector3 representation of the Quaternion and then convert the Vector3 back to a Quaternion using Quaternion.Euler.

Psuedo code:

 Vector3 rot = myTransform.rotation.eulerAngles;
 rot = new Vector3(rot.x,rot.y+180,rot.z);
 myTransform.rotation = Quaternion.Euler(rot);

Note that using euler representations of quaternion data can yield unexpected results (see: gimbal lock), so it is best to have clean data going in.

Hope that helps.

==

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 Heke · Jun 17, 2013 at 09:32 PM 0
Share

Okay now I tried it and it worked thanks a lot!

if someone is having the same issue, here'e my final code: edit: I added it to the main question.

avatar image nsevinc · Oct 15, 2018 at 10:21 AM 0
Share

thaks a lot it worked :)

avatar image
17

Answer by ikriz · Mar 13, 2014 at 04:43 PM

I find simply multiplying the value to work better and more readable.

 // multiply rotation by 180 on y axis
 transform.rotation *= Quaternion.Euler(0,180f,0);

 
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
avatar image
2

Answer by DaveA · Jun 17, 2013 at 05:48 PM

http://math.stackexchange.com/questions/39206/rotate-quaternion-a-by-180-degrees

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
avatar image
-1

Answer by jimprucey · Sep 14, 2017 at 06:28 PM

Thank you this worked great.

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
avatar image
0

Answer by vladibo · Sep 24, 2016 at 11:31 AM

https://github.com/vbodurov/unity-functions/blob/master/UnityFunctions/Assets/Scripts/Main/MiscTests/TestMoreThan360Rotation.cs#L40

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

21 People are following this question.

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

Related Questions

Ellipse Animation by code 2 Answers

Sprint position for gun 1 Answer

w in Quaternion? 1 Answer

Bone Rotation on X (or any) axis Issues 1 Answer

Unity Rotate Raycast on Quaternion 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