Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 youngapprentice · Aug 14, 2015 at 09:48 PM · physicsitweencurve

Navigate Curve at Constant Speed

Hi, all!

I've seen and read a lot of threads concerning iTween and traversing through paths at a constant speed. I have an example up and running right now that works perfectly, moving all objects around a curve at a constant rate.

The path in question is a flat oval (Much like a running track). For an object placed directly on a path, this works perfectly. I can have it move at, say, 15 units per second and it'll do that.

However, when I incorporate an offset with the curve, all objects sitting on the offset complete the curve in the same amount of time, because the math is tied to a time and not a speed in reality. It simply takes the speed and divides it by the length of the base curve and multiplies that by delta time. So although it purports to operate at a consistent speed, this is not quite true.

I know this because if I change the path length math to update the length in the equation based on the offset, it operates perfectly as a state function, but not in between start and end. As in; when a full revolution is complete, all of the objects are where they should be. But the spaces between them occur over the course of the run.

This should not be happening. The advances in spacing should technically only occur on the curves of the oval and not the straight sides, because when they are all moving at the 'same speed' in a straight line, no advances should be made.

I don't quite know how to deal with this. The code I borrowed from another thread works mainly with iTween Path Length and PutOnPoint functions.

I've gotten as far as calculating the maximum number of units an object should be able to travel in a given FixedUpdate. The next step should be to find what point on the curve from the current point is that number of units away. I am versed in calculus and am not afraid to use it but I am not quite sure about how to construct an algorithm to represent the curve.

Any help would be appreciated.

TL;DR: I want to move something along a curve in a way that keeps it at a steady units/second, taking into account any offset from the curve.

Thanks! - YA

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

3 Replies

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

Answer by youngapprentice · Aug 15, 2015 at 06:37 AM

So I figured it out by doing this:

Do some percentage math to clamp the distance travelled pretty close to what you want. Do math to find the exact distance you actually want to travel. Get the normalized vector in that direction and travel that exact distance.

Done :) Works like a charm.

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

Answer by Eno-Khaon · Aug 14, 2015 at 10:32 PM

I'm afraid I can't offer you an answer from experience yet, but since it appears you're looking to measure the length of bezier curves, I believe that you may be able to find the answers you're looking for between here and here.

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

Answer by cjdev · Aug 14, 2015 at 10:33 PM

From what I've seen of the tweening libraries, the curved paths are actually just a series of waypoints close enough together that they approximate the curve. If you find yourself needing to change the curve dynamically and update the speed you could always switch to a tweening function based on time and calculate the speed yourself based on the length of your new curve. All you'd need is the sum of the linear distance of the waypoints divided by your desired speed to give you the time used in the tween.

Comment
Add comment · Show 8 · 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 youngapprentice · Aug 14, 2015 at 10:45 PM 0
Share

I'd rather not change the speed dynamically, even if it does work for this reason: If I am traveling at 15mph, then I am definitely covering a very exact distance every second (Pretending my fixed update was every second). This is, in spirit, a little different than creating a fixed point change and fluctuating speed to make it look like the rate is consistent. I want to make it move along the curve, but also only cover a certain amount of real world units every update, ins$$anonymous$$d of a percentage of the curve.

avatar image cjdev · Aug 14, 2015 at 10:51 PM 1
Share

You wouldn't be finding a variable speed, only finding the new time for the tween based on the distance of the modified curve. Since distance = rate * time, with a constant rate (speed) you need to find the new time when the distance changes.

avatar image youngapprentice · Aug 14, 2015 at 10:54 PM 0
Share

Okay I follow that and that makes good sense. However, when if I do that and find a new time, this new time will be applied over the entire curve ins$$anonymous$$d of just on the parts where the distance discrepancy should be occurring. This will make gaps appear between objects on the straight points where these gaps wouldn't be appearing in real life if they were all moving at identical speeds.

avatar image youngapprentice · Aug 14, 2015 at 10:57 PM 0
Share

However, I think your solution could work if there was a way to splice the curve from moment to moment. For instance; the next 2 units of the curve ins$$anonymous$$d of the whole curve. Then it would work. I just can't figure out how to do this.

avatar image cjdev · Aug 14, 2015 at 11:08 PM 0
Share

In real life if two paths diverged in a curve, one to the outside and one to the inside, and two agents went at constant speeds along the curves to meet at a straight path the agent on the outside would be behind the agent on the inside. It's why racecar drivers always like to take the inside line.

Show more comments

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

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

Related Questions

integrating itween with physics 1 Answer

display arc for cannon's ball trajectory? 2 Answers

how to shot a soccer ball in curve path according to the swipe type 2 Answers

Moving rigidbody along spline, and being able to use physics 1 Answer

iTween not working within OnCollisionEnter? 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