• 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.

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

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

Input.GetAxis values returning to neutral in an inconsistent way? 0 Answers

Smoothly rotate object based on GetAxis 1 Answer

Is there a way to stop input.getaxis from returning to zero in script, without editing the controls ? 2 Answers

Flip over an object (smooth transition) 3 Answers

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