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 Grove121 · Jun 11, 2012 at 12:15 PM · movementvector3lerp

Vector3.Lerp Only working once

I'm trying to make a very simple AI script. All I want the enemy to do is travel to its target when a variable is no longer checked. When the game starts everything works how its supposed to, however when the variable is checked and the enemy waits (This gives the "player" a chance to move away). The next time the variable is unchecked, instead of traveling to the target like it did the first time, it instantly transports itself to the targets location. Any ideas on why this is happening?

 var duration : int = 3;
 
 var start : Transform;
 
 var end : Transform;
 
 var waiting : boolean = false;
 
 var targetObj : GameObject;
 
 private var targetScript : Target;
 
 
 
 function Awake (){                                                        
 
 targetScript = targetObj.GetComponent(Target);
 
 }
 
 
 
 function Update(){
 
     if(waiting == false){
 
         transform.position = Vector3.Lerp(start.position, end.position, Time.time/duration);
 
     }
 
 }
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
0
Best Answer

Answer by whydoidoit · Jun 11, 2012 at 12:20 PM

It works the first time because Time.time starts at 0. After that , it's going to be bigger than 1.

You need the last parameter of the Lerp to be a number between 0 and 1 - if it's 0 it's at the start position and 1 it's at the end position.

You would normally add Time.deltaTime to something to calculate it:

    var t : Float = 0;
    ...
    t += time.deltaTime;
    transform.position = Vector3.Lerp(start.position, end.position, t/duration);

And reset t when you want to start again.

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 Grove121 · Jun 11, 2012 at 12:25 PM 0
Share

That worked! Thank you!

avatar image whydoidoit · Jun 11, 2012 at 12:27 PM 0
Share

No problem :) Please mark the question as answered to get it off the list by clicking on the tick under my answer...

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

Vector3 Lerp using Time.deltaTime? 3 Answers

Smooth translation 2 Answers

Vector3 Lerp finish too quicly 1 Answer

How to smooth my camera (Vector3.Lerp) 0 Answers

Vector3.Lerp doesn't work on build 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