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 pkkr42 · Mar 23, 2012 at 03:33 PM · yieldvector

Vector3 Lerp, no smooth movement

i want my camera to smoothly move to the new position. unfortunatly this is not working. the script waits until the time is over and then it suddenly changes position, but doesnt interpolate between my 2 values. what am i doing wrong? also when i put a yield command in there my gui dissapears... heres my script, hope someone can help me..

 if (GUI.Button (Rect (6,60,100,20), "Set as Center")){ 
     var i = 0.0;
    var rate = 1.0/9;
    meineCam.GetComponent(Mouse).target = GameObject.Find(this.name +"target").transform;
 
 var oldPosition = Vector3(meineCam.transform.position.x, meineCam.transform.position.y, meineCam.transform.position.z);
 
 var newPosition = Vector3(GameObject.Find(this.name +"target").transform.position.x , GameObject.Find(this.name +"target").transform.position.y, meineCam.transform.position.z);
 
     while (i < 1.0) {
       i += Time.deltaTime * rate; 
     meineCam.transform.position = Vector3.Lerp(oldPosition, newPosition, i);
     }
  }

thanks a lot!

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 Berenger · Mar 23, 2012 at 03:56 PM

That's because no frame is drawn while your while is running. The engine just freezes until it's done. Try that instead :

 function OnGUI(){
     if( GUI.Button(...) ){
         ....
         MoveCamera(oldPosition, newPosition);
     }
 }
 
 function MoveCamera( oldPos : Vector3, newPos : Vector3 ){
     var t : float = 0.0;
     
     while (t < 1.0) {
         meineCam.transform.position = Vector3.Lerp(oldPos, newPos, t);
         yield null; // Here the while is paused until the next frame, so you actually see the camera moving.
         t += Time.deltaTime * rate;
     }
 }

PS 1 : Be carefull with my js syntax, i'm more of a C# guy.

PS 2 : Try not to do anything not-Event-related in OnGUI, like using Time.deltaTime. That function is called several times per frame and that will causes performances losses and unwanted behaviors.

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 pkkr42 · Mar 23, 2012 at 04:24 PM 0
Share

thanks man, works perfect in an extra function

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Yield And Return 2 Answers

Diagonal Movement 1 Answer

Problem setting references to GetComponent Script function return values 1 Answer

Object not rotating when the associated trigger is triggered 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