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 ineteye · Oct 13, 2012 at 06:20 PM · c#

Need help converting js to C# - rigidbody.rotation.z

Hi!

Need help to convert js line to C#:

 rigidbody.rotation.z = 0;
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 · Oct 13, 2012 at 07:01 PM 0
Share

alert ... this is totally and completely wrong. (heh!)

you can not modify the xyzw paramaters of a quaternion

it says so very clearly on the unity doco page.

it is very - very - confusing that unity used the letters "xyz" because the four paramaters of a quaterion have utterly no relationship at all to the three dimensions of space.

it is also simply a mistake that Unity allows them to be modified or looked at. there is absolutely no reason, ever, that you would look at them (far less set them). it's exactly like say, there'd be utterly no reason to look at the internals of PhysX as it's working, or whatever.

If you have advanced mathematical skills, you can read in 1000s of pages on the internet explanations of how quaternions are constructed, but it is irrelevant here. All you need to know to be a gem engineer is that they are a "thing" which can represent rotations, avoiding gimbal lock, and which for a good mathematical Group.

@ineteye, you can not do what you are trying to do.

(the fact that in c# you can't modify individual paras is irrelevant. TBC you cannot do that in javascript.)

avatar image Fattie · Oct 14, 2012 at 08:20 AM 1
Share

note guys ..

this http://unitygems.com would be incredibly helpful to you, note the quaternions article

1 Reply

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

Answer by Random username · Oct 13, 2012 at 06:37 PM

Hey, the problem is that you can't modify a single axis directly. Try doing this instead:

 Vector3 r = rigidbody.rotation.eulerAngles;
 rigidbody.rotation = Quaternion.Euler(new Vector3(r.x,r.y,0));

The reason I'm converting to euler angles is simply because Quartonians are dangerous to modify lol.

Comment
Add comment · Show 4 · 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 RC-1290 · Oct 13, 2012 at 06:55 PM 0
Share

Quaternions aren't dangerous to modify, they just don't work the same way, and can therefore behave in an unexpected way. $$anonymous$$odifying a quaternion like you would with Euler angles might rotate the GameObject in the wrong direction.

Or would you call that dangerous?

avatar image Fattie · Oct 13, 2012 at 07:03 PM 0
Share

referring to the internal four properties of a quaterion (which are badly named xyzw by Unity), the word "dangerous" is not really correct.

you can not achieve anything by modifying or reading the four internal values of a quaternion.

just as Random explains, you set or create a quaternion using the euler angles feature (or by building it from other quaternions, or handy functions like LookAt, etc etc)

avatar image Random username · Oct 13, 2012 at 09:20 PM 0
Share

Sorry, dangerous was a dumb word to use. I didn't mean it would literally, just that it's probably not going to do what you expect.

avatar image Fattie · Oct 13, 2012 at 09:26 PM 0
Share

right. it absolutely, definitely, will not do "what ineteye would expect" in his example!!!

your answer is perfect

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

12 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

Related Questions

js to C# - Instantiate(scoreParticle, object - Vector3(0,0,0.3), Quaternion.identity) 1 Answer

Need help C# -- yield, destroy 1 Answer

Need help converting js to C 1 Answer

Enemy AI script causing Unity to crash (Javascript to C#) 1 Answer

Need help converting js to C 2 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