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 Panik.Studios · Aug 25, 2012 at 09:27 AM · triggerplayerquaternion

Quaterion is rotating my character improperly?

When I hit trigger. Trigger is to rotate my character 90 degrees on the y axis. But for some reason it's rotating my character 180 degrees. I double checked there is no duplicate of the trigger.. and the scripts only on the trigger.... Ive tried setting the Quaterion to 45 just to see if it made a difference, but it doesn't, so I need advice.

Heres my script

 private var turn = false;
 function OnTriggerEnter (other:Collider){
 
 
     if(other.CompareTag("SSPlayer")){
         turn = true;
     }
 }
 
 function LateUpdate(){
 var player = GameObject.FindGameObjectWithTag("SSPlayer");
         
     if(turn == true){
         player.transform.rotation = Quaternion(0,45,0,0);
            var cam = GameObject.FindGameObjectWithTag("CamToggle");
         var cs = cam.GetComponent(CameraToggle);        
         cs.CamSelect = 1;
         var ssp = GameObject.FindGameObjectWithTag("SSPlayer");
         var sp1 = ssp.GetComponent(SSController);
         sp1.cont1 = 1;
         var sp2 = ssp.GetComponent(SSController2);
         sp2.cont2 = 1;
         turn = false;
     }
 }    

Thanks in advance to anyone who answers!

Comment
Add comment · Show 1
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 · Aug 31, 2012 at 06:47 PM 0
Share

Quaiternions are utterly unlike what you think.

It says extremely clearly in large letters here:

"never access or modify individual Quaternion components"

http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.html

Qiote simply, never access or modify individual Quaternion components.

1 Reply

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

Answer by Matt-Downey · Aug 25, 2012 at 10:40 AM

Quaternions are not what you think they are. Quaternions are an odd 4D space that will never faulter when doing rotations, but as a result it has absolutely nothing to do with Eulers Angles (which you are currently using). I lied a little in that there are links between the two, but you will have to learn the math from wikipedia or khan academy if you really want to use it.

What you want is the rotate method in the transform class.

transform.Rotate(0,90,0,Space.Self);

each class has tons of useful methods and variables in the API.

For instance: transform has Rotate, RotateAround, Translate, ViewportToRay, etc all of which you can see here.

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 Matt-Downey · Aug 25, 2012 at 10:51 AM 0
Share

Since I believe the background math is often more useful for understanding, the reason (0,90,0,0) will rotate the player 180 degrees lies in two major factors.

Firstly the squares of all factors (x,y,z,w) must add up to 1, so (0,90,0,0) is actually normalized to (0,1,0,0) before any calculations are made. [edit2: this is why (0,90,0,0) and (0,45,0,0) do the same thing, because they both become (0,1,0,0) due to normalization]

What happens next I'm a little shifty on, but unless you are multiplying by (0,0,0,1) [edit: or (0,0,0,-1)] the rotation will always change.

In this case (1,0,0,0); (0,1,0,0); & (0,0,1,0) might all rotate the player 180 degrees (just moving around different axes. The first case rotates the player around the x axis 180 degrees, second y, third z.

The larger the 4th value (dubbed w), the less the quaternion will change. Also here's Wikipedia Quaternion to Euler Page:

http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

The w, which is at the end in unity is at the beginning in almost all technical papers I've seen [it looks like this(w,x,y,z) normally]. Notice how (w,x,y,z) [convention] is alphabetical compared to Unity's (x,y,z,w).

avatar image Panik.Studios · Aug 25, 2012 at 08:04 PM 0
Share

I just changed it to player.transform.rotation = Quaternion.Euler(0,90,0);

avatar image Panik.Studios · Aug 25, 2012 at 08:05 PM 0
Share

Though, it rotated to 90.0001... That is a bit strange is it not?

avatar image Matt-Downey · Aug 31, 2012 at 06:38 PM 1
Share

That's a rounding error, you can ignore it. It has to do with a problem called drifting (it is what it sounds like).

Floating point numbers are not 100% accurate, luckily though most of the decimal places are entirely unnoticable (floats count 6-7 digits places). For instance, for the mouse cursor to drift an extra degree (which in itself is hard to notice), it would probably take 10,000 frames, which at 60 frames a second won't happen very fast.

Banks handle data differently because they know if money starts drifting upwards, the pennies will start to add up, so they never use floating point numbers as far as i know but ins$$anonymous$$d "long"-type numbers or large or big (or something like that, I forget).

This article could be down your alley if you want to learn about drifting (you also learn methods of fixing it, but it's more for the knowledge than in the attempt to fix the problem, since drifting won't break your game (aside from animations in very long games as mentioned in the article)): http://gamasutra.com/view/news/173606/Indepth_$$anonymous$$atrices_rotation_scale_and_drifting.php

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

9 People are following this question.

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

Related Questions

rigidbody.velocity not working on x axis 2 Answers

Trigger on reaching target rotation only working the first few times. 1 Answer

Activate Object with trigger and if leave then inactivate 2 Answers

Action activates trigger. 1 Answer

Player hanging on objects. 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