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 Merrick · Mar 27, 2014 at 03:49 PM · scripting problem

Basic Lerp question

Hi everyone, I'm extremely new with Unity and scripting.

I have an object that when it apear I need it to go from world origin to the specific Vector3 (0,0,8)

But I can't seem to find the mistake I'm doing. This is the script that I wrote for the object. Is pretty simple:

{ public float speed;

 void start ()
 {
     transform.position = Vector3.Lerp(transform.position, new Vector3 (0,0,8), Time.deltaTime * speed);
 }


}

I also tried with a void awake and nothing...

Help! Anyone?

Comment
Add comment · Show 4
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 Destran · Mar 27, 2014 at 03:51 PM 0
Share

try giving speed a value like public float speed = 3. and also start needs to be capitalized like Start()

avatar image Lo0NuhtiK · Mar 27, 2014 at 03:54 PM 1
Share

Also, put your lerp in Update() or use a coroutine since Start() is only ran once.

avatar image Destran · Mar 27, 2014 at 03:58 PM 0
Share

That too ^^

avatar image Professor Snake · Mar 27, 2014 at 04:08 PM 0
Share

You also need to capitalize the s in Start.

1 Reply

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

Answer by Curb · Mar 27, 2014 at 04:07 PM

The Start function will only execute on one frame. A lerp is usually used to animate an object over multiple frames. One way of doing this would be to make a coroutine:

 IEnumerator MoveObject(float duration){
     float t = 0;
     
     Vector3 currentPos = transform.position;
     Vector3 newPos = new Vector3(0,0,8);
 
     while (t < 1){
         t += Time.deltaTime / duration;
         transform.position = Vector3.Lerp (currentPos, newPos, t);
 
         yield return null;
     }    
 }

Then call it from somewhere with:

 StartCoroutine(MoveObject(3));

The 3 is the duration of the animation. You could build in even more parameters between the () of course.. such as the new position. But this should get you going. :)

Comment
Add comment · Show 3 · 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 Merrick · Mar 27, 2014 at 06:39 PM 0
Share

This worked great!! It's exactly what I wanted. Can I ask you why the rutin is a IEnumerator? I thought that was for geting aligned a series of numbers.

avatar image Merrick · Mar 27, 2014 at 06:49 PM 0
Share

TY all for your answers

avatar image Destran · Mar 27, 2014 at 06:51 PM 0
Share

it's an IEnumerator because it's a Coroutine. Any function with a yield statement is a coroutine. Don't forget to mark Curb's answer as correct :D

http://docs.unity3d.com/Documentation/$$anonymous$$anual/Coroutines.html

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

24 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity freezing on Waitforsecond 1 Answer

How do I apply gravity, but only in the y-axis? 2 Answers

Root motion or script motion to make a character like riven? and any suggestions for learning resources 0 Answers

How to make ad appear after a few seconds? 1 Answer

How to create a script that displays a text box when the user collects an item?,How to create a script that displays a text box when the user collects an object? 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