dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Beziers to Paths with Inertia

  1. #1
    Senior Member
    Join Date
    Aug 2000
    Posts
    264
    Hi all,

    I wonder if anyone has any ideas about how to move a mc along a chosen bezier curve, but to add inertia to it also?

    Basically i've got a bezier curve you adjust and choose the path (curve) a ball will take. For now I just animate the ball along the original bezier points, but this provides rigid motion, i need it to ease out, but still follow this bezier!

    It's quite complex to explain the code, you can get the files at which will explain it better:

    http://www.paperscreen.co.uk/shared/alpha.fla
    http://www.paperscreen.co.uk/shared/alpha.swf

    Just roll mouse over ball to adjust bezier, then click once to kick the ball (it's a football game!) You'll see what i want to happen, the ball just needs to ease-out to look more realistic!

    Cheers

    Sam


  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    Very interesting.

    I know nothing about bezier curve. But I'll like to follow any replies in this thread.

    Can you explain with more details about "i need it to ease out, but still follow this bezier! " ?

    Slowing down ? Or X follow the curve, but Y jumps high ? You talked about inertia, but will that make the ball out of the curve ?

    Thanks.

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Posts
    264
    Hi ericlin

    At the moment the bezier points are just created at an interval of 1/noOfPoints. This creats a path like:

    medium o- - - - - - -o medium

    I need it to create each path point easing out like:

    fast o- - - - - --o slow

    I need to know what to do with the interval, so the bezier is still the same curve, but the points get closer together towards the end!

    Cheers

    Sam

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    I tried modify the n; The effect is not very good. And maybe the difference can only be seen when you slow the frame rate a little.

    Code:
    if (released && n<=noOfBezierPoints/2) {
    		nextpoint = _root.getNextPoint(count);
    		_x = nextPoint.x;
    		_y = nextPoint.y;
    		_xscale = 100-count*(level*2.2);
    		_yscale = 100-count*(level*2.2);
    		n++;
    		level += 2;
    		var total = noOfBezierPoints/2;
    		var k = total*total/(total-1);
    		var n2 = k-k/n;
    		count = detail*2*n2;
    }

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Posts
    264
    Hi ericlin,

    hope you had a good weekend!

    Thanks for attempting this, you sure got further than me! I see what you are doing although this ok, but probably not precise enough. I'm gonna need adjustment of the inertia to be more refined i think!

    I've updated the bezier code, this should be far more easier to understand than the original long-winded functions, this is a much more self-contained!

    Anyone any other thoughts on animating along a bezier but with inertia instead of point by point?

    Here's my new bezier function:

    // cp1, cp2, cp3 are bezier control points
    // b1-3 are the bezier quadratics

    var attach = true;
    var resolution = 1/15;
    function drawspline () {
    var num = 0;
    for (var i = 0; i<=1; i += resolution) {
    var b1 = i*i;
    var b2 = (2*i*(1-i));
    var b3 = (1-i)*(1-i);
    var px = _root.cp1._x*b1+_root.cp2._x*b2+_root.cp3._x*b3;
    var py = _root.cp1._y*b1+_root.cp2._y*b2+_root.cp3._y*b3;
    ++num;
    if (attach) {
    _root.attachMovie("point", "point" add num, num+10);
    }
    _root["point" add num]._x = px;
    _root["point" add num]._y = py;
    }
    attach = false;
    }
    drawspline();


    Regards

    Sam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center