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
1
Question by sotirosn · Oct 07, 2013 at 12:45 AM · curvefollow pathcurved path

how to follow curved path?

If I want an object to travel from point A to point B, but also want the object to start from facing its own forward direction to facing aligned with a direction B.forward, then what is the best way to implement this? So far I calculate a bezier curve with my own script, but I cannot find the length of the curve which I need so that the object can travel at a constant speed. Some solutions talk about evaluating the curve numerically but this seems inefficient for many moving objects.

Example this would be a way a car moves from point A to point B.

Comment
Add comment · Show 1
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 Fattie · Feb 22, 2015 at 07:29 AM 0
Share

simply get "SuperSplinePro" from the asset store. it does everything and everyone uses it for everything. its as essential as a text editor.

4 Replies

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

Answer by demented_hedgehog · Jan 23, 2015 at 01:24 PM

iTween does what you want I believe (available for free in the asset store).

Edit... apparently Super Splines Pro is very good be sure to look at that as well.

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 Fattie · Feb 22, 2015 at 07:30 AM 0
Share

true but SSP is just .. well there's no point not having it, it does it all and pretty well

avatar image demented_hedgehog · Feb 22, 2015 at 10:05 AM 0
Share

Fattie has a lot more experience about this stuff than I do. So make sure you check out SSP here: Super Splines Pro

avatar image
1

Answer by aldonaletto · Oct 07, 2013 at 01:17 AM

If you really want to follow some curve, maybe this whydoidoit's article may help you. On the other hand, if you just want to move in the object's forward direction while turning gradually to the target, do exactly this: calculate each frame the target direction, Slerp a little to it and then move the object in its current forward direction:

 public var speed: float = 5.0; // linear speed in m/s
 public var turnSpeed: float = 1.5; // rotation speed control
 
 var target: Vector3; // assign the target position to this variable
 
 function Update(){
   // update direction each frame:
   var dir: Vector3 = target - transform.position;
   // calculate desired rotation:
   var rot: Quaternion = Quaternion.LookRotation(dir);
   // Slerp to it over time:
   transform.rotation = Quaternion.Slerp(transform.rotation, rot, turnSpeed * Time.deltaTime);
   // move in the current forward direction at specified speed:
   transform.Translate(Vector3(0, 0, speed * Time.deltaTime));
 }

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 sotirosn · Oct 07, 2013 at 05:02 AM 0
Share

This almost works, but I arrive at the point (which is actually a transform) not facing in its forward direction. So i guess my example is more like driving a car into a garage or parking space.

avatar image aldonaletto · Oct 07, 2013 at 01:17 PM 0
Share

Yes, the object keeps looking towards the target, not to the target's forward direction - doing this will require a curved path evaluation, for sure: if the target is facing the previous target, for instance, a curve around the target must be created so that the object enters it in the correct direction.

avatar image nicomaque.jette · Dec 24, 2014 at 08:42 AM 0
Share

Old thread but the idea may help someone... Previous comment from 'aldonaletto' plus adding an empty object really far (infinite!) in the target's forward direction and using a Transform.LookAt on this one.

avatar image
0

Answer by Fattie · Oct 07, 2013 at 11:44 AM

note that mathematically, points on bezier curves over equal T are approximately equidistant only.

http://stackoverflow.com/questions/4089443/find-the-tangent-of-a-point-on-a-cubic-bezier-curve-on-an-iphone

But it is utterly inconceivable that it would matter in a video game.

What you normally do is simply look at (literally use "LookAt" in unity) a number of points ahead (say, 4 points ahead -- try different values -- 3, 2, 5 etc -- for the best look).

This is precisely how any race game you've ever played works.

Again it's utterly impossible to know what you're trying to do .. unless you tell us, even in the most general terms. What is the domain of speed etc? (Is this a 2D arcade game? a parking simulator? a race game? flight game in 3D? or?)

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 sotirosn · Oct 12, 2013 at 04:04 AM 0
Share

I am making a hamster game, I have hamsters that are first roa$$anonymous$$g around the bottom of a cage and then climb up some tubes. It looks funny if they walk to the enter point, pivot on a point, and then jump in. The bezier curve works with but the hamsters do not hold constant speed. I have been looking into the maths and they are much more complicated than I thought.

avatar image sotirosn · Oct 12, 2013 at 04:06 AM 0
Share

Actually what I am really having a hard time finding is curvature at any point, so I can update my hamster to walkLeft or walkRight animation. The only thing that works at the moment is calculating the tangent of two circles that defined the maximum turn radius of the hamster. Then the hamster follows the circle, goes straight, goes around a second circle and is there.

avatar image Fattie · Feb 22, 2015 at 06:10 PM 0
Share

you simply need SSP. it would be insane to program it from scratch. what you describe would literally take 20, 30 seconds with SSP.

it would be like if you "did not use" unity's UI and for some reason got in to program$$anonymous$$g buttons on your own, and handling image display and stuff. SSP is the only solution

avatar image
0

Answer by 0x73DB07 · Sep 26, 2014 at 08:02 PM

FWIW, I've begun using Curvy (http://www.fluffyunderware.com/pages/unity-plugins/curvy.php), and if your application depends heavily on splines, I would say it's worth the money. No relation to the developer, just a user.

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

20 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

Related Questions

How to generate a curve from a model ? 2 Answers

Access curves presets from c# 1 Answer

2D simple road system with curves and intersections 0 Answers

moving forward after bazier curve 1 Answer

Camera always 90 degrees to player (curved path) 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