Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 WillHops · Jun 14, 2019 at 05:12 AM · rotationgetaxisvector3.angle

Help with Quaternion.AngleAxis

So I'm trying to get my Camera to rotate around a single game object when I hold down the Middle Mouse Button.

My script works fine when rotating the camera around Vector3.up, but when rotating around Vector3.forward the camera moves up and down even though I am only moving the mouse down.

The problem I can see clearly, as the camera rotates, its "forward" rotation axis changes (this doesn't happen when rotating around "up" axis).

The solution? No idea, thanks in advance for your help! :)

Here's the code:

 private void Update()
     {
         if(Input.GetMouseButton(2))
         {
             camTurnAngle = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * rotateSpeed, Vector3.up);
             camTurnAngle = Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * rotateSpeed, Vector3.forward);
             camera_offset = camTurnAngle * camera_offset;
         }
         transform.position = targetShip.transform.position - camera_offset;
         transform.LookAt(targetShip.transform);
     }

Comment
Add comment · Show 2
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 WillHops · Jun 12, 2019 at 06:44 PM 0
Share

Any ideas?

avatar image highpockets WillHops · Jun 13, 2019 at 10:57 PM 0
Share

Ok not sure what you’re trying to do with this code. The camTurnAngle is a quaternion rotation and the second time you call AngleAxis, it will always overwrite the first call you make on the line before, so this doesn’t make any sense and I don’t understand how it could be working on the y axis either. I’m trying to wrap my head around camTurnAngle * camera_offset.. What is camera_offset?? A float?? A vector?? Because you are multiplying the quaternion by that and then subtracting the product from the target position which is also a strange calculation. Please explain, what is camera_offset and what do you expect camTurnAngle to be?? As right now it is a quaternion.. cheers

1 Reply

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

Answer by pmerilainen · Jun 14, 2019 at 09:39 AM

If you'd check your code you can clearly see you overwrite the camTurnAngle value with the second Quaternion.AngleAxis. You should multiply quaternions if you want them to 'stack'. But bear in mind that quat multiplication is not commutative eg q1 x q2 does not equal q2 x q1

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

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

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

Related Questions

GetAxis difference between mobile and mouse 0 Answers

Scale gameObject 1 Answer

Problem with gameObject.transfrom.rotation and GetAxis 0 Answers

Smoothly rotate object based on GetAxis 1 Answer

Input.GetAxis values returning to neutral in an inconsistent way? 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