Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 lvictorino · Jun 19, 2012 at 10:01 AM · camerarotationquaternion

How to force camera rotation?

Very simple here, I know... But I think I'm lost.

I've coded a script to control my camera and here is what I do to handle mouse control:

 void LateUpdate() {
     
     if (camlock == false) {
         _x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
         _y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
         
         Quaternion rotation = Quaternion.Euler(_y, _x, 0);
         
         _myTransform.rotation = rotation;
     }
 }

It works pretty fine. But when player will press a button I'd like to force the camera position and orientation. I've tried using:

     transform.rotation = Quaternion.LookRotation(my_new_rotation_vector3);

But the rotation is not good (due to the lateUpdate method computing _x and _y according to Input.GetAxis() I think).

Any idea on how I should do to force camera rotation? should I use quaternions? If yes how?

Thank you.

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 whydoidoit · Jun 19, 2012 at 10:19 AM 0
Share

So do you have a vector you want the camera to look at or an actual orientation?

avatar image lvictorino · Jun 19, 2012 at 10:31 AM 0
Share

I must admit that I don't know the difference between both. But yes, I have a vector3 defining where the camera has to look.

avatar image whydoidoit · Jun 19, 2012 at 10:36 AM 0
Share

And the Vector3 you have is a position not the description of the rotation around 3 axes?

Quaternion.LookRotation() looks down a vector which is a direction.

avatar image lvictorino · Jun 19, 2012 at 11:02 AM 0
Share

Yes it's a position not a rotation around axis.

1 Reply

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

Answer by whydoidoit · Jun 19, 2012 at 10:37 AM

This will modify the current camera rotation by the mouse, allowing you to set another rotation. Drop your _x and _y variables.

  void LateUpdate() {
 
     if (camlock == false) {
        var rot = transform.rotation.eulerAngles;
        rot.x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
        rot.y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
 
        _myTransform.rotation = Quaternion.Euler(rot);
     }

 }
Comment
Add comment · Show 2 · 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 lvictorino · Jun 19, 2012 at 11:01 AM 0
Share

Thanks. I'm a bit ashamed it was so obvious and I didn't think of it.

avatar image whydoidoit · Jun 19, 2012 at 11:02 AM 0
Share

We all do that kind of thing, all the time :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A little help with this camera script please? 3 Answers

Lerp Third Person Camera Rotation 1 Answer

Camera rotation script logic error? 0 Answers

Checking for quaternion values to not be NaN 4 Answers

Rotation, my script shouldn't work but does. 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