Constant Speed iTween

What’s the proper way to make an object follow a path using iTween at a constant speed?

Is there a specific easetype I should use?

I would guess EaseType.linear…

That’s what I would guess too. However, even using linear, objects still slow down on curves.

The key to consistent speed on paths with iTween really lies with evening out the space between your points. Sorry that’s the limitation of things until I can figure out a way to interpolate evenly regardless of the point placement.

1 Like

I had the same problem with iTween and I started to use the Antares Project. It has a functionality to create smooth curves that can be travelled at a constant speed with little code. As pixelplacement1 said, the key is spacing evenly the control points and Antares Project do it automatically, but I like more the interpolation method used by iTween…

I wish iTween included that functionality, but meanwhile, I use Antares Project for smooth path creation and iTween for everything else.

If I get time maybe I’ll bug the talent behind the Antares Project and try to fix this issue.

Cool, thanks for the responses guys.

I really enjoy iTween, but the lack of constant speed is an issue for me. It’s good to hear that you’re going to look at
it eventually, pixel. Until then, I’ll just play with the points a bit and see what I can do.

Thanks again!

I know that time is the scarcest resource, you have done a great job so far I’m sure you’ll make iTween even better when you have time. I was only providing a “temporal workaround” until you have time to include that functionality in iTween. By the way, if I get some money with my current project, I will donate some money to you and the Antares Project creator: both of you have helped me a lot and you deserve it.

Hi, you should be able to replace your interpolation mechanism for the curves with a hermite algorithm - this will give you a constant rate 0->1.0 for the length of a curve and thus give you the ability to do constant speed. I’ll look at what modifications iTween needs for this - I suspect it should be able to be made an ‘addon’.

Cheers,
Dave Lannan

Awesome! Let me know.

I’m glad to hear this issue is being addressed. I love iTween already (just started with unity) but the speed thing was confusing me as dispite paying for examples I thought I was doing something wrong. I’d love to see the fix!

Any update to this thread?

Still in progress and still trying to figure out a solution…

Been looking up how to do calculus. This is going to take me a while to learn. I figured I might post this here since some of you might get some info from it. Any real programmer will be able to learn and implement it faster than me.
http://www.geometrictools.com/LibMathematics/CurvesSurfacesVolumes/CurvesSurfacesVolumes.html

More importantly

Also, upon further reading I have come accross what needs to be done for those with know how. Apparently you need to reparameterize the curve so that all the points are equal distance to each other. I am going to try and make a Bezier Curve script that gives you archlength, bezier curve, and allows you to go from one curve to another. Again, I have to learn calculus first, but meh, my studies have been going well for now.

Hey, any updates on this?

Also interested on a fix or workaround for this issue!

I don’t know if you still need this, but I developed a simple solution that works just fine for my purposes.
You have to create your path with the iTweenPathEditor and then add the C# script iTweenConstantSpeed.
Then you have to set two variables:
Amount → This variable takes care to go through all your path. The bigger, smaller will be the “pieces” of the path.
Distance → This variable takes care of the distance between points.

You see: one method to keep an equal velocity during a curve is to set all the waypoints with the same distance between them. And that’s what my script does. It divides all the path into several waypoints with the same distance between them.

I hope you enjoy it and it fits your purposes.

947586–35454–$iTweenPathConstantSpeed.unitypackage (39.3 KB)

Hm, to which object should i attach the script? I attached it to the pathholder object, and got an object reference error. I attached it to the object that should move along the path, and got an object reference error too.

so, maybe I’m making this easier then it’s supposed to be but I’ve worked around this problem with iTween by using MoveTo (Next Point in Path), the distance to the next point used to alter the speed and the onComplete parameter to start the tween again for the point after the next point… easier to code then to say…

var path : Vector3[ ];
var nextPoint : int = 0;
var speed : float = 10.0;

function Start () {
Tween();
}

function Tween () {
var toPoint : Vector3 = path[nextPoint];
var distance : float = Vector3.Distance(toPoint, transform.position);
iTween.MoveTo(gameObject,{“position”:toPoint,“time”:distance/speed,“easetype”:“linear”,“oncomplete”:“Complete”});
}

function Complete () {
nextPoint++;
if (nextPoint < path.Length) Tween();
}

Hi,

I am currently working on solving this very problem, unfortunately Felipetnh’s solution isn’t quite right.
To get rid of your errors, you need to rename the GetPath name to the name of your path that you created with iTweenPathEditor, like this…
If your path in named “Path1” then you need to modify this line to…

position = iTweenPath.GetPath(“Path1”);

This should now work if you attach the script to the same object you attached your path to, and will show the extra WayPoints that the script creates…
The solution isn’t quite right because it simply adds more points to the path by dividing the total length into more WayPoints, so a long straight will still result in faster movement along that straight. To see what I mean, create a smallish path on a 4x4 plane, with about 10 points, 1 longish straight and a few twisty turny bits, it’ll move faster along the straight.

The solution is a little more complex but fairly easy to do using Felipetnh’s as a base, the path needs to be sub-divided further into perhaps 10,000 pieces, then a minimum distance for a WayPoint should be defined as say “d”, step through the smaller 10,000 distances until the minimum required distance is met “d”, then use this as a new WayPoint. This needs to be done as simply dividing the path into smaller distances for WayPoint would still make the traversing of the path non-constant, but somewhat less variable as it was with say 10 WayPoints. Stepping along in micro-steps until the desired distance for a waypoint is met is much more accurate and will result in a constant speed along the path…

So do I have the code? …Nope not yet, just sussed out what I need to do and I’ll work on this either over this weekend, or early next week when I get time and post up the results for you and anyone else that needs it…

My solution “should” work, although I’ve not tried it yet it does make sense, so the code may change slightly, but it will result in a constant speed when I’ve finished with it…

I need this too because my path’s can be drawn by the user, then my code has to re-interpret those paths, draw the GFX, and make the waypoints at equal distance so the speed can be controlled. This seems the most logical way to me to do it, as it prepares a new array of points before the code is run alleviating processor workload . Doing the Maths in real time as some others have suggested, on the fly in the Update function, so to speak will result in unnecessary processing when the game is running, plus I need my game to work on iPhone etc…

Will post back soon, maybe you’ve sussed your error already, but my update to this problem will come shortly…