# iTween even velocity

 0 I'm trying to find a way to move an object evenly along an iTween path. Linear easetype doesn't work since the length of the path between each node will effect the object's speed (this is the same using time or speed). It is the same with PutOnPath and PointOnPath and their use of percent.For example here is my path (even if it's strait it does this): A------------------------------B--C--DThis is an extreme example to demonstrate the problem, but in this case the object would go really fast from point A to B and then slow down from B to D.I don't want the speed to be altered so a character's walking animation will remain believable. Is there a way to make this happen with iTween? I'm thinking I would at least have to be able to locate the closest point on the path, have the character look at a point slightly ahead of that, and then move forward at it's own velocity. It's that first step I don't know how to do. But I'm open to any solution for this. Any ideas? more ▼ asked Dec 13 '11 at 06:58 AM grzdvd 16 ● 3 ● 4 ● 4 Yes, have the same problem...That makes the speed param a bit useless and the time param look foolish, because you expect the speed to be constant. Jan 02 '12 at 10:18 PM WhiteKnight OP- could you please rearrange your many posts here to consolidate them in a single, chronologically-ordered place? It's kind of confusing as it is here, since answers aren't sorted by the order they are first posted in, and it makes this difficult to read. Remember that you can always edit any of your old posts. Jan 11 '12 at 06:33 AM syclamoth Hey syclamoth,They are in order. I think grzdvd has replied via 'answer' rather than comment that's all.Cheers Jan 11 '12 at 12:35 PM markhula add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

sort voted first
 0 I had the idea to pre-calculate the distortion of each segment while configuring the path. It seems to work ok. First I created a class to hold the distortion of each segment class SplineSegment { public float StartPercentage; public float EndPercentage; public float Length; public float Distortion; } Then I calculated all of the values and placed them in a queue var pathLength = iTween.PathLength(array); var normalisedSegmentLength = pathLength / (array.Length - 1); pathSegments = new Queue(); for (int i = 0; i < (array.Length-1); i++) { var float_i = (float)i; var segmentLength = iTween.PathLength(new Vector3[] { array[i], array[i + 1] }); pathSegments.Enqueue(new SplineSegment() { Length = segmentLength, StartPercentage = (float_i / (array.Length - 1)), EndPercentage = ((float_i + 1) / (array.Length - 1)), Distortion = normalisedSegmentLength / segmentLength }); } Finally, I update the position in the fixed update void FixedUpdate() { if (progress > pathSegments.Peek().EndPercentage) pathSegments.Dequeue(); progress += Time.deltaTime * speed * pathSegments.Peek().Distortion; iTween.PutOnPath(gameObject, path, progress); } A bit of extra work, appears functional more ▼ answered May 16 '12 at 08:39 AM Mr_Snuffle 15 ● 1 ● 1 ● 1 Very nice! Jan 24 at 09:17 PM mcroswell add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Ah, I figured I couldn't have been the only one having the problem, but the lack of responses made me think otherwise. Still wrote up a quick solution in case, sorry for the lack of detail and code. I actually put the solution together in uScript, so the code it generated for it probably isn't best for learning how to do this. But maybe I can help you and we can provide the community with a good sample.What part of my description is tripping you up? It's okay to say the beginning, I just want to know where to start working from. There's also the possibility I left something out since I wrote it up quick. more ▼ answered Jan 04 '12 at 01:14 AM grzdvd 16 ● 3 ● 4 ● 4 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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(); } more ▼ answered Jun 28 '12 at 11:13 PM add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x427
x318
x239

asked: Dec 13 '11 at 06:58 AM

Seen: 3382 times

Last Updated: Jan 24 at 09:17 PM