Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Project_BP · Jan 28, 2015 at 11:05 AM · cameraguitransformlerpslerp

3D menu camera rotation issue.

Hello Community,

Trying to create a 3D main menu here. The main camera have to rotate around a single point to bring into the FOV other 3D buttons. So click on "Settings" to rotate the camera to the Settings Menu. The main camera is a chid of the object CameraCenter (tagged with "CameraCenter") where the rotation should be applied to.

My actual code is failing to work the way it should. The Rotation stops after few degrees. Where is my mistake?

     #pragma strict
     
     // button variables
     var Title = false;
     var Play = false;
     var Settings = false;
     var Quit = false;
     var Back = false;
     var ButtonSmooth = 2.0;
     var ButtonMove = 2.0;
     
     private var mouseover : int;
     private var defaultPos : Vector3;
     private var newPos : Vector3;
     
     // camera variables
     var CameraRotatinonSmooth = 2.0;
     var CameraRotationAngle = 180;
     var CameraCenter : GameObject;
     
     private var defaultRot : Vector3;
     private var newRot : Vector3;
     
     
     function Start()
     {
         CameraCenter = GameObject.FindWithTag("CameraCenter");
         defaultPos = transform.position;
         newPos = new Vector3 (defaultPos.x, defaultPos.y, defaultPos.z + ButtonMove);
         defaultRot = transform.eulerAngles;
         newRot = new Vector3 (defaultRot.x, defaultRot.y + CameraRotationAngle, defaultRot.z);
     }
         
     // buttons moving toward camera
     function Update ()
     {
         if(mouseover == 1)
         {
             renderer.material.color = Color.blue;
             transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * ButtonSmooth);
         }
         if(mouseover == 0)
         {
             renderer.material.color = Color.white;
             transform.position = Vector3.Lerp(transform.position, defaultPos, Time.deltaTime * ButtonSmooth);
         }
     }
     
     function OnMouseEnter() 
     {
         mouseover = 1;
     }
     function OnMouseExit() 
     {
         mouseover = 0;
     }
     
     function OnMouseDown()
     {
         if(Title)
         {
     //        DO SOMETHING NICE
         }
         if(Play)
         {
             Application.LoadLevel(1);
         }
         if(Settings)//camera rotation to settings part
         {
             CameraCenter.transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, newRot, Time.deltaTime * CameraRotatinonSmooth);
         }
         if(Back)//camera rotation back to main menu
         {
             CameraCenter.transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * CameraRotatinonSmooth);
         }
         else
         {
             Application.Quit();
         }
     }

Ps. already tryed to commit the rotation via CameraCenter.animation.Play. Works fine, but i would apritiate a script only solution to have more tuning possibilities.

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

1 Reply

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

Answer by Scribe · Jan 30, 2015 at 12:32 PM

Your problem is that OnMouseDown is only called once, and so your Slerp methods only get called once with a small t value and then stop and aren't called again.

You could handle it similarly to how you save the mouseover number and then do an action in update while that number is something or alternatively you could use coroutines to handle the action over some amount of time an example to follow (my UnityScript knowledge is a little rusty so they may be a few errors):

 ...
 
     if(Settings)//camera rotation to settings part
     {
         StartCoroutine(CameraRotate(CameraCenter.transform, newRot, 1/CameraRotatinonSmooth));
     }
 
 ...
 
 function CameraRotate(trans : Transform, endRot : Vector3, time : float){
     var startRot : Vector3 = trans.eulerAngles;
     var t : float = 0;
     
     while(t <= 1){
         trans.eulerAngles = Vector3.Slerp(startRot, endRot, t);
         t += Time.deltaTime/time;
         yield null;
     }
     trans.eulerAngles = endRot;
 }


this way it will continue until CameraRotate has finished even is OnMouseDown is not called again.

Scribe

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 Project_BP · Jan 30, 2015 at 01:15 PM 0
Share

Wow Scribe, thank You! It works perfectly. :)

avatar image Scribe · Jan 30, 2015 at 01:29 PM 0
Share

You are welcome :) Thanks for marking as accepted!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

NGUI- lerping widget on Y Axis only working in one direction 0 Answers

Camera Lerp from A to B, and back 2 Answers

Use Lerp Position and Slerp Rotation together 0 Answers

Quaternion Slerp Sanity Check 1 Answer

Keep GameObject on a corner of the screen 1 Answer


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