This basically ensures that the tangents match where the curves meet.
![flash actionscript 3.0 bezier curve flash actionscript 3.0 bezier curve](http://www.pxleyes.com/blog/wp-content/uploads/2010/07/splashScreen_flashcs3.jpg)
So for example if the common anchor point is at (0,0) and the closest control point of one of the curves is at (-4,5) then the closest control point of the other curve must be at (4,-5) in order for the curves to join smoothly. In addition, the distance between each of the two closest control points (to the common anchor point) must be the same and they must be exactly opposite of eachother (relative to the common anchor point). Without going into too much detail basically the condition is that the end anchor point of one curve must be the beginning anchor point of the other. After doing some more Wiki reading I found out that there is a condition which when met allows two Bezier curves to be connected smoothly. So naturally I decided I needed more than one Bezier curve. Making the PathĪlthough a single cubic Bezier curve can describe a pretty versitle path it just wasn’t enough to make an entire train track out of. But I didn’t end up using this as I will explain later. Of course the more control points you have in between the anchor points, the more twists and turns the curve can have.Īnother reason why I chose Bezier curves is that Flash has a built in function for drawing Bezier curves. The points in between are control points and they describe points where the curve should be tangent. These describe the beginning and end of the curve. Every type of curve has two anchor points. Since I wanted the track to be as flexible as possible I chose to use cubic Bezier curves. The more points you have to control the curve, the more “flexible” the curve can be.
![flash actionscript 3.0 bezier curve flash actionscript 3.0 bezier curve](https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/images/localconnection_samedomains.gif)
A Bezier curve is basically a parametric curve described entirely by only 4 points (cubic), 3 points (quadratic) or 2 points (linear). I did some research on path following and when I came across Bezier curves I knew that it would be the perfect solution. I wanted the track (path) to be able to freely take any shape (to some extent). I wanted the player to be able to customize the track but I didn’t want to rely on a grid system. I wanted to make a game with a train track and a train following the track.
![flash actionscript 3.0 bezier curve flash actionscript 3.0 bezier curve](https://i.ytimg.com/vi/P_IYRLd2X2U/maxresdefault.jpg)
My particular case used a train track for the path and train carts as the objects, but it can apply to anything.
#Flash actionscript 3.0 bezier curve how to
I’m going to talk about how to create a path dynamically in Flash and have objects follow this path.