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 /
This question was closed Feb 03, 2016 at 10:43 AM by Soundlag for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Soundlag · Nov 04, 2014 at 05:14 PM · camerarotationerrorquaternionmatrix

Quaternion To Matrix conversion failed because input Quaternion is invalid

I suddenly got this error. I don't know what went wrong. I can still play my game, but I get this error when I slide my character.

 using UnityEngine;
 using System.Collections;
 
 public class CameraController : MonoBehaviour {
 
     private GameObject player;
     PlayerController playerController;
 
     public float cameraHeight = 4;
     public float cameraDistance = 4;
     public float smooth = 3;
 
     private float newCameraHeight;
 
     private int direction;
 
     // Use this for initialization
     void Start ()
     {
         player = GameObject.Find ("Player");
         playerController = player.GetComponent<PlayerController>();
 
         transform.position = new Vector3 (player.transform.position.x, cameraHeight, player.transform.position.z);
         newCameraHeight = cameraHeight;
     }
     
     // Update is called once per frame
     void Update ()
     {
         float speed = playerController.runSpeed;
         direction = playerController.getDirection ();
 
         if(newCameraHeight < cameraHeight)
         {
             cameraHeight -= 0.1f;
         }
         else if(newCameraHeight > cameraHeight)
         {
             cameraHeight += 0.1f;
         }
 
         Vector3 MoveTo = new Vector3 (player.transform.position.x, cameraHeight, player.transform.position.z);
 
         switch(direction){
         case 0:
             MoveTo += new Vector3(0, 0, -cameraDistance);
             break;
         case 1:
             MoveTo += new Vector3(-cameraDistance , 0, 0);
             break;
         case 2:
             MoveTo += new Vector3(0, 0, cameraDistance);
             break;
         case 3:
             MoveTo += new Vector3(cameraDistance , 0, 0);
             break;
         }
 
         transform.position = Vector3.MoveTowards (transform.position, MoveTo, speed);
 
         Vector3 LookAtVector = new Vector3 (player.transform.position.x, player.transform.position.y + 2, player.transform.position.z);
 
         // Create a rotation based on the relative position of the player being the forward vector.
         Quaternion neededRotation = Quaternion.LookRotation(LookAtVector - transform.position);
         
         // Lerp the camera's rotation between it's current rotation and the rotation that looks at the player.
         transform.rotation = Quaternion.Lerp(transform.rotation, neededRotation, smooth * Time.deltaTime);
     }
 
     public void changeHeight(float height)
     {
         newCameraHeight = height;
     }
 }
 

Comment
Add comment · Show 4
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 smoggach · Nov 04, 2014 at 07:51 PM 0
Share

The only insight I can provide is that it may be due to changing the position AND the rotation in the same frame. When you change the position of something that is rendered by a perspective camera, that object's rotation is changed to suit the perspective. Then in the same frame you try to change the rotation again and something inside unity goes kaput for a sec.

avatar image Soundlag · Nov 04, 2014 at 10:41 PM 0
Share

Any suggestions how to fix it?

avatar image smoggach · Nov 05, 2014 at 02:35 PM 0
Share

nothing pretty... I wonder if using a coroutine would help?

avatar image smoggach · Nov 05, 2014 at 02:55 PM 1
Share

Hey I just fixed $$anonymous$$e by moving some scaling code from Update() to LateUpdate(). Is there anything scaling your transform while you move and rotate it?

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by Bunny83 · Nov 05, 2014 at 03:11 PM

Personally i never had an issue like that. The only thing i can think of is that LookRotation has a problem creating a valid rotation since it looks like you're camera is facing upside down and you don't pass an up-vector to LookRotation. That means it uses "world up" (aka Vector3.up) as up vector. If you look straight down it can't determine the rotation around your look direction since the up vector is parallel to your look vector. You might want to calculate a valid up vector for your LookRotation call. The up vector defines how the quaterniion is rotated around the look axis. It doesn't have to be exact 90° to the look axis but it need to be different from your Look axis.

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Quaternion to Matrix Conversion Error - Camera Script 0 Answers

Quaternion - Euler Angles, weird variable swapping when converting 2 Answers

Gun Rotation 2 Answers

Gameobject Rotation Calculation 0 Answers

Quaternion to Matrix conversion failed, but I'm not doing anything with either?? 6 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