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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Pauls · Oct 19, 2013 at 02:04 PM · pathslerpbezier

curved path, Slerp issue?

Hi,

EDIT : Solved with this :

 void Update () {
         if ( Input.GetKey("d") ) start = true;
         if ( start ){
             myTime = Time.time;
             start = false;
         }
         car.position = Vector3.Slerp( myArray[0], myArray[1], Time.time - myTime );


I don't understand why the first code does not work (the car just stops at the first point in the array, and does not move), and it works with the second code, when I use car.position into the Slerp method :

 //#1
 car.position = Vector3.Slerp( myArray[0], myArray[1], 0.6f );
 
 //#2
 car.position = Vector3.Slerp( car.position, myArray[1], 0.6f );

  .

The #1 code comes from this source : http://whydoidoit.com/2012/04/06/unity-curved-path-following-with-easing/

Thanks for your help

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 robertbu · Oct 19, 2013 at 02:57 PM

Slerp() like Lerp() is designed to take a changing value between 0 and 1 as the last parameter. These functions slide between the two parameters. For example take this function call:

 car.position = Vector3.Slerp( myArray[0], myArray[1], t ); 

When 't' is 0, the function returns entirely myArray[0]. When 't' is 1.0, it returns entirely myArray[1]. When 't' is in the middle it returns a mix of the two with the value of 't' determining how much of each is used in the calculation. So when you have:

 Vector3.Slerp( myArray[0], myArray[1], 0.6f );

It is saying that based on the definition of Slerp(), use 40% of myArry[0] and 60% of myArray[1]. And since everything is constant, the return value never changes. This is the traditional/intended use of Lerp() and Slerp(). Now enter your second line of code:

 car.position = Vector3.Slerp( car.position, myArray[1], 0.6f );

It is like your first equation, but you change the starting point each frame. So the first time, it is called it returns a point 60% between the current position, and myArray[1], but then it moves the starting point. The second time it calculates a new position 60% between the two and moves the starting position. It is kinda like the thought experiment where you are asked to walk halfway to the goal each day. You get close quickly, but you never arrive at your destination.

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 Pauls · Oct 19, 2013 at 03:27 PM 0
Share

Thanks! I edited my message with the right code, thanks for your 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

14 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

Related Questions

creating path e moving object on it 1 Answer

iTween, HOTween, Spline Controller and Others 1 Answer

3D Text to follow a path; iTween 0 Answers

How to create a Mesh in a Closed Bezier Curve/Path 0 Answers

Keep the player on a path? 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