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 JustinTheSwift · Jul 04, 2018 at 11:11 PM · quaternionslerpquaternionscamera rotationeuler angles

Difficulty making a complex camera rotation

I'm creating a turn based game set in space in which two teams of players are on opposite sides of a three-dimensional playing field. The white team and black team begin the game with the same orientation, except that the white team is rotated 180 on the Y axis and also rotated 180 degrees on the X axis (meaning the two teams are facing each other and one team is upside down).

To make play even between turns, I need the camera to perform a complex rotation so that both players can control their own team from the same perspective on their turn. My goal is to have either player, at the beginning of his own turn, facing toward the right side of the screen with his head up toward the top and his feet down toward the bottom. My goal is to make a smooth camera rotation from (0,0,0) to (180, 0, 180) or (0, 180, 180), and then make it go back when the turn changes again.

I am not having a problem changing the position of the camera so that it points at the correct team, but I am having trouble with the rotation.

In attempting to solve this problem, I have created a focal point around which the camera orbits. When a turn change begins, the variable slerpOnBlack or slerpOnWhite turns to true. As long as this variable is true, one of the following two methods will fire on every update:

 void SlerpCameraBlack(){
     if (new Vector3(CameraFocus.transform.rotation.x, CameraFocus.transform.rotation.y, CameraFocus.transform.rotation.z) != new Vector3(0, 0, 0)) {
         CameraFocus.transform.rotation = Quaternion.Slerp (CameraFocus.transform.rotation, Quaternion.Euler(new Vector3(0, 0, 0)), (10*Time.deltaTime));
     } else {
         SlerpOnBlack = false;
     }
 }

 void SlerpCameraWhite(){
     if (new Vector3(CameraFocus.transform.rotation.x, CameraFocus.transform.rotation.y, CameraFocus.transform.rotation.z) != new Vector3(0, 180, 180)) {
         CameraFocus.transform.rotation = Quaternion.Slerp (CameraFocus.transform.rotation, Quaternion.Euler(new Vector3(0, 180, 180)), (10*Time.deltaTime));
     } else {
         SlerpOnWhite = false;
     }
 }

Use of these functions results in inconsistent results which I do not understand, and which lead me to believe that I must not understand clearly how to use quaternions.

Can anyone help me resolve this?

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
0
Best Answer

Answer by JustinTheSwift · Jul 05, 2018 at 12:09 AM

Evidently this was a rounding problem. My camera was slerping to almost the position it was supposed to reach, but wasn't actually reaching it. As such, the SlerpOn booleans never turned to false. This caused the camera to get stuck between the black and white positions. I solved the problem by rounding my numbers and forcing blackSlerpOn to turn false when whiteSlerpOn is true and vice versa.

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

Answer by hectorux · Jul 04, 2018 at 11:44 PM

You are comparing a x,y,z of a Quaternion instad of the Euler angles of your camera, try changing in the comparison the "rotation" to "eulerAngles"

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 JustinTheSwift · Jul 05, 2018 at 12:06 AM 0
Share

Whether or not your solution might have helped I can't say, but I've come up with a solution without it. Thanks for helping anyway.

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

89 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

Related Questions

Tilt first person camera's z axis while turning 0 Answers

Is transform.rotation in Quaternions? 2 Answers

How to fix flipping Euler anlges? 0 Answers

Addition Quaternion 0 Answers

Smoothly rotating a gameObject 90 degrees on a button press and being able to rotate it in the opposite direction off of the same button. 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