Jump to content
Search Community

MotionPath - progress value problem

szaqal test
Moderator Tag

Recommended Posts

hi I'm getting a weird progress value after tweening MotionPath progress property. I've created a CirclePath2D object (it progress prop is set to 0). Next I've calculated the progress change value:

 

var progress_change:Number = circle_motion_path.anglesToProgressChange(circle_motion_path.progressToAngle(circle_motion_path.progress), -1110, Direction.COUNTER_CLOCKWISE);
// result: -0.08333333333333333

 

Finally I'm tweening:

 

TweenLite.to(circle_motion_path, 5, {progress: circle_motion_path.progress + progress_change, onComplete: navigationToStopComplete});

 

and trace'ing the circle_motion_path.progress prop in the navigationToStopComplete function results: 329.99999999999994 instead of 330. I'm guessing that this has something to do with the floating point math but I'm not sure.

 

How can it be fixed?

 

Please help.

Link to comment
Share on other sites

Right, if you're getting 329.99999999999994 instead of 330 that's almost surely a biproduct of working with binary numbers and floating point math which is unrelated to any of the GreenSock code. If you need a round number, you could use Math.round() on the result. I wish I had a simple solution for you, but if you Google about this sort of thing you'll quickly see that it's a very common issue that plagues virtually all software. Normally it's not a big problem, though, because the user will never notice a difference in rotation between 329.99999999999994 and 330 :)

Link to comment
Share on other sites

Yep, I've found many articles about it. In my case it's generating a random error because I've a conditional like this:

 

if(progress > 1 && progress < 0)
{
  ...
}
else
{
  // very important actions
}

 

and it is very important for me that progress is 0 not "almost" 0. I've fixed this by rounding progress prop to 12 decimal places. I hope it will work.

Link to comment
Share on other sites

Jack one more thing about MotionPath. How can I calculate "rotation" value of MotionPath? By "rotation" I mean the number of full revolutions based on progress value change. So lets say if I'm changeing the progress from 0 to -0.0833333

 

TweenLite.to(circle_motion_path, 2, {progress: circle_motion_path.progress + (-0.0833333)});

//circle_motion_path.progress is 0

 

the "rotation" value should be 0.083333 and so on. In other words CCW direction should increase "rotation" value and CC should decrease it.

 

Could You give me some advice how can I achieve that?

Link to comment
Share on other sites

In Flash, rotation increases in the CW direction, not CCW.

 

I'm not sure I understand your question. If you want to change the rotation of the CirclePath2D, you can do that as easily as:

 

myCirclePath.rotation = 90;

 

Or tween it or whatever.

 

If you need to track how many times it has fully rotated, you'd need to do that on your own. In Flash, rotation is always reported as being between 180 and -180 and a CirclePath2D's progress is always reported between 0 and 1. You can, of course set these values to whatever you want and they'll translate for you, like if you set the rotation to 270 in Flash and then traced it, you'd get -90. If you set progress to 2.5, you'd get back 0.5.

 

If that doesn't help, could you maybe restate the question in a different way or provide a visual indication of what you're asking?

Link to comment
Share on other sites

I've created a custom CirclePath2D class in with I've overridden the set progress function (see attached) so that I could calculate the progress change on flight. I'm tweening the progress value like this:

 

var direction:String = Direction.COUNTER_CLOCKWISE;
var progress_change:Number = -0.08333333; // it can also be -2.5 or 0.012222222 - it is beeing calculated dynamically
TweenLite.to(circle_motion_path, 2, {progress: circle_motion_path.progress + progress_change,
						onStart: motionPathDirection,
						onStartParams: [direction]});
//circle_motion_path is CustomCirclePath2D object
//circle_motion_path.progress is 0 on start

private function motionPathDirection(direction:String):void
{			
circle_motion_path.direction = direction;
} 

In onStart function I'm setting manually the direction of progress change to "tell" what kind on calculations should be made in overridden set progress function.

 

But this doesn't always work well as I've made it. Especially when quick jumping from progress: 0 to progress: -1.25.

 

Is it clearer now? Please chech this link to see the example: http://pszajna.ires.pl/index.html maybe it will explain the problem better. Each time I'm jumping to next point I want to calculate how the progress value changes from point 0 to point 1.

Link to comment
Share on other sites

I just uploaded a new version of MotionPath and PathFollower, both of which now have a "rawProgress" property that's the same as "progress" but it doesn't re-interpolate the values to always be between 0 and 1. This means you can easily tell how many times things have wrapped. For example, if you tween rawProgress to 3.5, progress will end up at 0.5 but rawProgress will be 3.5.

 

From what I can tell by looking at your file, this was the missing link that you needed. Right?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...