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 W1k3 · Nov 20, 2013 at 04:48 AM · vector3lerploadloadlevel

Vector3.lerp doesn't work when level is loaded

I've been having having a big problem with lerp. I though it was a problem with the builder, but through trial and error, I discoverd that the lerp function doesn't work when a level is loaded. If the game starts on the level, it's fine, but when I use Application.LoadLevel("alevel"); the lerp function doesn't work.

I also don't think it is directly to do with my code because I've used something as complex as this:

 public class Upgrades : MonoBehaviour {
 
     public lives script;
     public AudioClip blip;
     bool on;
     
     void Awake(){
         renderer.enabled = false;
         on = false;
     }
     
     void OnMouseEnter()
     {
         transform.localScale = new Vector3(0.16f, 0.16f, 1f);
         if(on == true){
         audio.PlayOneShot(blip, 1.0F);
         }
     }
     
     void OnMouseExit()
     {
         transform.localScale = new Vector3(0.12f, 0.12f, 1f);        
     }
     
     void Update() {
     
         if(lives.livesleft <= 0){
             renderer.enabled = true;
             on = true;
         }
         if(player.paused == true){
             renderer.enabled = true;
             on = true;
         }
         else if(player.paused == false && lives.livesleft >= 1)
         {
             renderer.enabled = false;
             on = false;
         }
     }
     
     void OnMouseDown()
     {
         if(on == true){
             Application.LoadLevel("Shoot stuff in space");
         }
     }
 }

To as basic as this:

 public class test : MonoBehaviour {
 
     void Update () {
         transform.position = Vector3.Lerp(transform.position, new Vector3(100.0f, 20.0f, 1.0f), 10f * Time.deltaTime);
     }
 }

And the result is the same. I tried different game objects, different scenes, different scripts but the level being loaded is the only thing in common so far.

I'm loosing my mind so any help would be fantastic.

Comment
Add comment · Show 2
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 robertbu · Nov 20, 2013 at 05:22 AM 0
Share

I took your basic script and tested it. It worked fine on the load of a new level. I don't see a Lerp() in your first script.

avatar image W1k3 · Nov 20, 2013 at 05:42 AM 0
Share

I uploaded the wrong script for the first one. $$anonymous$$aybe something is wrong with my computer for all I know; it beats me why it's not working. I took supernats advice, and it turns out that the proper vector 3 lerp works. Thanks though.

1 Reply

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

Answer by supernat · Nov 20, 2013 at 05:14 AM

I think the problem is that you are using Time.deltaTime as your lerp factor. Maybe you meant to do this, but I can't see how this would ever be useful to set a transform position. DeltaTime is the amount of time passed since the last frame was run, and it fluctuates. The lerp factor should always be 0.0 to 1.0. I would take another look at what you are trying to accomplish and choose a different approach.

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 robertbu · Nov 20, 2013 at 05:32 AM 0
Share

@supernat - The use of Time.deltaTime as a Lerp factor is a common approach and is used frequently in answers on UA. It works because the current position (transform.position in the code above), is updated each frame. The result is that the object moves approximately the same fractional amount towards the destination each frame, but since the distance is shrinking, the distance moved each frame is shrinking. The result is an eased movement towards the destination. Note this approach might fail if there is a large deltaTime on the load of a scene since the "fraction" might be larger than 1.0. A quick hack to test if this is an issue would be to not do the Lerp() if deltaTime is above some threshold...say .01 and see what happens.

avatar image supernat · Nov 20, 2013 at 01:51 PM 0
Share

Ahh, I see your point, never considered using it that way. I'll have to keep this trick in $$anonymous$$d, I usually add easing the hard way.

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

18 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

Related Questions

Move Transform to Target in X seconds 3 Answers

make my gameobject lerp between points more smoothly 0 Answers

Vector3 Lerp mis-match 0 Answers

[Solved] PlayerPrefs Vector 3 Defaulting to 0,0,0 1 Answer

moving between two points over time 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