In this section of the book, Keith Peters mention that in order to do a natural walk cycle, we need to swing forth and back and synchronizing them. Thus, we had to apply sine formula to it. We can modify our script in Kinematics by:
1) make segment0 point downward by adding 90 degree to it rotation and reducing it range of motion in both direction to 30 degree
2) Reduce segment1 range to 30 degree and then add another 30 to it. This make the rotation range from 0 to 60, thus it will only bend in one direction.
For more information on more walk cycle, please read up on Foundation Actionscript 3.0 Animation. I just here posting what i had learnt and understand from the book.
var sl:Number=segment0._width;
// increasing rotate angle for segment0 var cycle:Number=0;
// limit rotating angle by a max value from 90 degree var offset:Number=30;
this.onEnterFrame=function():Void{
kinematic();
}
function kinematic():Void{
// return segment1 position relative to segment0 with(segment0){
cycle+=.05;
_rotation=90+Math.sin(cycle)*offset; var a:Number=_rotation*(Math.PI/180); // find angle of rotation var xPos:Number=_x+Math.cos(a)*sl; var yPos:Number=_y+Math.sin(a)*sl;
}
// rotate segment1 together with segment0
segment1._rotation=segment0._rotation+offset+Math.sin(cycle)*offset;
// get segment1 final position
segment1._x=xPos;
segment1._y=yPos;