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 iarnazca · Jul 06, 2014 at 01:57 PM · cameramovement

Camera not moving smoothly from point a to point b

In my scene I have a small room. Depending on the menu items you choose I want the menu to close, the camera to move to its next destination, and the menu to open again with its new options.

Currently the camera does move to the correct destination but it's an instantaneous switch. The camera just kind of teleports over there instead of moving slowly.

Here is the code I have.

This is an example of a menu window function.

 void playWindow(int windowID)
     {
         //Leave a gap from the header.
         
         GUILayout.Space(15);
         
         
         if(GUILayout.Button("Practice", GUILayout.Height(buttonHeight)))
         {
                         
             //Play against AI
             
         }
         
         
         GUILayout.Space(10);
         
         if(GUILayout.Button("Online", GUILayout.Height(buttonHeight)))
         {
             //find a partner
             
         }
         
 
         GUILayout.Space(10);
         
         if(Application.isWebPlayer == false)
         {
             if(GUILayout.Button("Back", GUILayout.Height(buttonHeight)))
             {
                 target = startCam ;
                 showPlayMenu = false ;
             }
         }
         
         
     }


Here you'll notice that the target variable is set to 'startCam' when the 'back' button is pushed.

This is part of the scripts update() function that causes the camera to move.

 void Update () {
         int userId = loginScript.userId ;
         bool loggedIn = loginScript.loggedIn ;
         if (loggedIn == false){
             Application.Quit();
         }
 
         //Debug.Log ("ran");
         if (loggedIn == true) {
             if (showBarMenu == false && showDeckMenu == false && showPlayMenu == false && playing == false && buildingDeck == false ){
                 showMainMenu = true ;
             }
         }
 
         float step = cameraSpeed * Time.deltaTime;
         Camera.main.transform.position = Vector3.MoveTowards (target.transform.position, target.position, step);
         //TODO: camera does not move smoothly.
 
         //rotate camera to be the same rotation as targetCam
         mainCam.transform.rotation = target.transform.rotation ;
         
 
 
 
 
 
     }


The camera's rotation happens instantly and I just through that code in there because the previous movement code wasn't functioning correctly.

I realize that that will not work.

Is the vector3 movement not working because I need to tell it to continue on the next frame some how? I thought Time.deltatime would do that for me. How do I make the camera glide to its new destination instead of appear there?

Comment
Add comment · Show 1
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 meat5000 ♦ · Jul 06, 2014 at 08:02 AM 0
Share
 float step = cameraSpeed * Time.deltaTime;

Your step is a constant. You will only get one movement from your step.

Update() is automatically called once a frame. You need to change step each frame.

1 Reply

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

Answer by flaviusxvii · Jul 06, 2014 at 02:06 PM

 Camera.main.transform.position = Vector3.MoveTowards(target.transform.position, target.position, step);

First of all, these variable names are super-silly. This reads as.. moving from target which is a GameObject maybe.. to target.. which is a transform. So there are two things named target and they're not the same type of thing. That can't possibly work. It's bad. Super bad. Know this is really bad.

You should try something more like this:

 Camera.main.transform.position = Vector3.MoveTowards(Camera.main.transform.position, target.position, step);
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 iarnazca · Jul 08, 2014 at 10:16 PM 0
Share

That just about completely fixed the problem. I was moving it from its target to its target which was getting me that teleport like behavior.

Thanks flaviusxvii.

Now i'll fumble my way through the rotation as well.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UNITY 3D: How to make the camera follow the player? Smoothly 2 Answers

How do I add a camera bounce effect every time the player lands? 0 Answers

Rotate 3rd person camera around player 1 Answer

Constrain a GameObject's movement to an orthographic camera's viewport bounds 4 Answers

RTS Mouse Click Movement 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