Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
0
Question by Thor · Apr 28, 2011 at 07:02 PM · camerarotationcamera-movementquaternions

Rotating a camera and his object like an airplane simulator

Hi All, i'm totally new to Unity, and what i'm trying to test in this moment is rotating a shape to have it to move like an airplane. For my first step i'm ignoring physics,rigidbodies and so on. What i want to achieve are these objectives: 1) when i move my mouse up, it has to go down (related to its facing) 2) when i move my mouse right it has to roll on its Z axis. I produced some code that doesn't work, the rotations looks randomly and from time to time it looks like it goes in gimbal lock.

Could please someone suggest me the correct direction to follow? Thank you.

this is the wrong code.

// rigidbody.AddForce( ( transform.forward ) * playerSpeed ); rotationZ = Input.GetAxis("Mouse X") * xSensitivity * 0.02f ; rotationX = Input.GetAxis("Mouse Y") * zSensitivity * 0.02f ;

Quaternion newRotation = new Quaternion( rotationX , 0 , rotationZ ,1);

if( (rotationZ != 0) || (rotationX != 0) ) { target.transform.rotation = Quaternion.Slerp(target.transform.rotation, newRotation , Time.deltaTime ); }

Comment
Add comment
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

2 Replies

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

Answer by sneftel · Apr 28, 2011 at 09:20 PM

There's not much need for Slerp()ing here, if I'm understanding your requirements. Just call target.transform.Rotate(), with the euler angles based on your X and Z rotations. By default, Rotate() specifies the rotation relative to the current orientation, which is what you want for something like an airplane.

Comment
Add comment · Show 3 · 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 Thor · Apr 29, 2011 at 07:16 AM 0
Share

thank you for your answer, doesn't rotate with euler angle suffer of gimbal lock?

avatar image Jesse Anders · Apr 29, 2011 at 03:22 PM 0
Share

@Thor: Working directly with Euler angles can indeed introduce gimbal lock, but this won't be a problem when using Transform.Rotate() to apply local, incremental rotations on a per-update basis.

avatar image sneftel · Apr 29, 2011 at 08:07 PM 0
Share

Indeed. Gimbal lock is a problem which is related to perturbing an orientation which is stored as Euler angles, not to representing that perturbation in terms of Euler angles. Unity internally uses Quaternions to represent object orientation, so this isn't a problem here.

avatar image
1

Answer by Jesse Anders · Apr 28, 2011 at 09:13 PM

Your first problem is here:

Quaternion newRotation = new Quaternion( rotationX , 0 , rotationZ ,1);

The elements of a quaternion don't represent rotation angles in any direct way. Any good reference on quaternions will explain how the rotation is encoded, but suffice to say that you rarely (if ever) want to construct a quaternion directly or modify its elements directly when working with Unity.

I didn't look at your code too carefully beyond that, but I think the above is the first problem you'll want to address.

Comment
Add comment · Show 1 · 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 Thor · Apr 29, 2011 at 07:15 AM 0
Share

thank you for your answer, i'll check the question more deeply

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

No one has followed this question yet.

Related Questions

[JS] Custom camera rotation resets on Var change? 0 Answers

Rotating the camera over a period of time 1 Answer

Rotate object instead of camera around it? 0 Answers

Forward and back movements with a camera emulating an isometric view 1 Answer

How do I get my camera to rotate around the y=0 coordinate it's looking at? 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