• 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 /
  • Help Room /
avatar image
0
Question by AlfEspinosaN · Jan 22, 2019 at 07:47 PM · rotationquaternionlookateulerangleslookrotation

Problem with Quaternion and Euler Angles

I receive the input from an xbox controller to move the camera into a Vector3:

     camMove = new Vector3(Mathf.Clamp(camMove.x + input.y * -1 * sensitivity, -90f, 90f), camMove.y + input.x * sensitivity, 0 );    

Then, if I make a score, the camera looks at the score stats in a tv of the game. BUT, I want to let the player keep moving their stick from that position/rotation.

         Quaternion daRot = Quaternion.LookRotation(lookatStat.transform.position);

         mainCam.transform.rotation = daRot;          
         camMove = mainCam.transform.eulerAngles;
         
         mainCam.transform.eulerAngles = camMove;


So, what happens is that the camera looks at the score, and when it updates the euler angles, it just looks to the ground really abruptly, as if the euler angles or the rotation was different than what I supposedly saved in camMove.

Why is this happening?

Comment
Add comment · Show 5
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 xxmariofer · Jan 22, 2019 at 09:22 PM 0
Share

what are you suppost to be doing here?

      cam$$anonymous$$ove = mainCam.transform.eulerAngles;
      
      mainCam.transform.eulerAngles = cam$$anonymous$$ove;

since both lines just makes no sense, you save the transform eulerangles of the actual camera and in the next line update the eulerangles with the same vector?

avatar image AlfEspinosaN xxmariofer · Jan 24, 2019 at 07:57 PM 0
Share

this line is always beign updated cause the controller input is cam$$anonymous$$ove: mainCam.transform.eulerAngles = cam$$anonymous$$ove;

But, when I make a score, I rotate the camera with LookAt to the score tv. Now, what I do is that I save the euler angles from the main camera into the cam$$anonymous$$ove variable:

cam$$anonymous$$ove = mainCam.transform.eulerAngles;

So that in the next line: mainCam.transform.eulerAngles = cam$$anonymous$$ove; starts from that position saved and starts recording the controller inputs.

avatar image DCordoba · Jan 22, 2019 at 11:38 PM 0
Share

u have a mess with assign and know the purpose of variables, maybe u need to check the classic algoritms to view a wise organization of variables, u initialize daRot with the position of the score, and later use it to set rotation on cam, well its ok but u can do this on just one step

 mainCam.transform.LookAt(lookatStat.transform);

u later give the value to the cam position to u buffer cam$$anonymous$$ove replacing the value calculated checking the commands, and also give it to camera position, so with this lines u arent doing nothing, just reasign the same value

      cam$$anonymous$$ove = mainCam.transform.eulerAngles;
      
      mainCam.transform.eulerAngles = cam$$anonymous$$ove;

I think u just want to do some

      mainCam.transform.forward += cam$$anonymous$$ove;

and leave the all rotation calculus to unity engine.

hope this helps.

avatar image AlfEspinosaN DCordoba · Jan 24, 2019 at 08:03 PM 0
Share

It´s just that actually these lines:

  cam$$anonymous$$ove = mainCam.transform.eulerAngles;
   
   mainCam.transform.eulerAngles = cam$$anonymous$$ove;

are like this:

 if (lookAtScore)
    {
         Quaternion daRot = Quaternion.LookRotation(lookatStat.transform.position, Vector3.up);

         mainCam.transform.localRotation.SetLookRotation(lookatStat.transform.position);      
         cam$$anonymous$$ove = mainCam.eulerAngles;
         lookAtScore = false;
     }

because I store the euler angles from the main camera when they are looking at the score into the cam$$anonymous$$ove variable. The cam$$anonymous$$ove variable also stores the controller inputs, so that is why this next:

mainCam.transform.eulerAngles = cam$$anonymous$$ove;

so that now we can start checking the controller inputs from the position where our mainCamera is. I forgot to put those brackets, but I still don´t get why the camera starts looking below after I stored the euler angles of the main camera into cam$$anonymous$$ove.

avatar image Owen-Reynolds · Jan 22, 2019 at 11:44 PM 1
Share

I think LookRotation is being used wrong. It takes a "vector" arrow as input, for example LookRotation(target-source). Using it with only a target gives you the rotation if you're sitting at (0,0,0).

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 1 Answer

Delayed LookAt, but only on one axis 1 Answer

Rotating an Object (To Face Another Object) Only on X and Y Axis 3 Answers

Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation. 1 Answer

Rotation issues - Please help 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges