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 Ozale · Mar 12, 2013 at 11:44 PM · movementarraylerp

Move continuously through array of Vectors

I need to move an object through an array of Vector3 coordinates smoothly. I've written similar code before, but moving from [a] to [b], then from [b] to [c] etc. means that for one frame the object is stationary. Does anybody know how to move through a list of Vectors continuously?

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 robertbu · Mar 13, 2013 at 12:12 AM 0
Share

Unless you actually need to hit the vertices, the trick to not stopping is to figure out how far the calculated distance would take you past the next vertex and start the next line that far in.

avatar image Ozale · Mar 13, 2013 at 12:32 AM 0
Share

That could work, but how could I calculate how much distance is actually covered per frame? Wouldn't it depend on framerate?

avatar image robertbu · Mar 13, 2013 at 12:37 AM 0
Share

You define a rate of movement as units per second. Then at each frame, you multiply it by Time.deltaTime;

 dist = speed * Time.deltaTime;

So dist is how far you will travel. If that distance is more than is left in the current line, you use the remainder starting from the next vertex.

avatar image Ozale · Mar 13, 2013 at 12:42 AM 0
Share

I think I follow. On each frame of this movement we compare distance to the target, and if the distance to target is less than or equal to 'dist', we set the new target as the next vector in the array, but either calculate our starting position with the 'extra' as a negative offset, or simply translate from our current position.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Eric5h5 · Mar 13, 2013 at 02:17 AM

Using MoveObject,

 var points : Vector3[];
 var time = 5.0;
 
 function Start () {
     for (var i = 0; i < points.Length-1; i++) {
         yield MoveObject.use.Translation (transform, points[i], points[i+1], time, MoveType.Time);
     }
 }

Since MoveObject advances the third parameter of Lerp by using Time.deltaTime before setting the position, the object will never be stationary for one frame at the transitions, since it will never quite be at the starting point specified by the points in the array (though it will always end up exactly at the ending point).

Comment
Add comment · 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

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

11 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

Related Questions

Lerp Movement Pauses after frame 2 Answers

Getting a 2d Sprite to move over time to an Array 1 Answer

Lerp Movement Forward Help 2 Answers

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

Movement Script 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