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
1
Question by stingman · Jun 05, 2013 at 10:41 PM · rotationerrorquaternionmatrixconversion

Quaternion to Matrix Conversion Error - Camera Script

I've made an alteration to the smooth follow script and I'm running into some Quaternion errors after making the changes. I've figured out that if I remove one variable (the time variable from the forward transform) from the script the error goes away but then the rotation is very choppy. Thus I need to multiply it by the time variable to keep a smooth rotation.

Here is the main section of the script:

 void LateUpdate() {
         
         if (!isStarting) {
         // Calculate the current rotation angles
         float wantedRotationAngle = player.transform.eulerAngles.y;
         float currentRotationAngle = transform.eulerAngles.y;
         
         // Damp the rotation around the y-axis
         currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
         
         // Convert the angle into a rotation
         Quaternion currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
         
         // Set the position of the camera on the x-z plane to:
     // distance meters behind the target
     transform.position = player.transform.position;
     transform.position -= currentRotation * Vector3.forward * distance;
     transform.forward += player.transform.forward * rotationDamping * Time.fixedDeltaTime;
 
     // Set the height of the camera
     Vector3 currentPosition = this.gameObject.transform.position + new Vector3 (0, height, 0);
     this.gameObject.transform.position = currentPosition;
         }
         else
         {
             transform.position = Vector3.Lerp(transform.position, player.transform.position + new Vector3(0, 7, 0), 2.0f * Time.deltaTime);
             transform.rotation = Quaternion.Lerp(transform.rotation, player.transform.rotation, 2.0f * Time.deltaTime);
         }
     }



The Quaternion to Matrix Conversion error is as follows: Quaternion To Matrix conversion failed because input Quaternion is invalid {-0.591886, -0.335223, -0.285926, 0.676890} l=1.002638

The error is coming from the line: transform.forward += player.transform.forward rotationDamping Time.fixedDeltaTime;

If I remoeve the Time.fixedDeltaTime I don't get the error anymore but then the rotation is very choppy and looks awful.

Any help out there? Thanks!

Comment
Add comment · Show 3
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 Graham-Dunnett ♦♦ · Jun 06, 2013 at 09:23 AM 0
Share

Why are you using fixedDeltaTime inside LateUpdate? fixedDeltaTime is the time between calls to FixedUpdate. Also, by setting forward directly you are effectively setting the rotation matrix component of the Transform. You probably need to make sure that your change to forward doesn't invalidate right and up.

avatar image stingman · Jun 06, 2013 at 01:13 PM 0
Share

I forgot to change it back before posting this. I was using regular deltaTime. I was just trying fixed to see if that could be the issue. If I used Time.time ins$$anonymous$$d of deltaTime the error goes away though. But again the rotation is not smooth. It's slightly odd. I had a feeling that setting forward directly might be the issue, but as soon as I removed the frame rate dependence then it doesn't work... so I thought hey maybe someone can see what's going on here. At this point I might just try and write something else, ins$$anonymous$$d of altering the smooth follow script. Too bad, because if this error could go away the script does exactly what I want :) Thank you for your help though.

avatar image Graham-Dunnett ♦♦ · Jun 06, 2013 at 02:47 PM 0
Share

Well, as I said, because you are changing the forward vector only, the 3x3 matrix that is the rotation component of the transform is no longer orthogonal. Think of it this way, forward, right and up form the corners of a cube. You've changed the direction that forward points in. If this was a cube, then right would change also. You can think of this as the cube being rotated around the up vector. In your case, only forward has changed, and right still points whereever it used to. This means the cube is now sheared and these three vectors are no longer at ninety degrees to each other. Thus your rotation matrix is no longer orthogonal. Unity has tried to use a quaternion during the maths, and concluded that the matrix is impossible to create. (In quaternion terms, the quaternion should have a unit length, but it doesn't. I guess whether Unity spots the problem or not depends on how much your forward vector deviates, which leads to the quaternion changing length.) I still think you'd be better off computing the angle you want forward to rotate through, and then rotate the axes as a whole.

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

Quaternion To Matrix conversion failed because input Quaternion is invalid 1 Answer

How do I do operations with a Vector3 and a Quaternion? 2 Answers

Creating a Matrix4x4 from an Object's Transform 1 Answer

Gun Rotation 2 Answers

How to Decompose a TRS Matrix? 3 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