Brian Chia
       
 
categories
actionscript
actionscript 1.0
actionscript 2.0
misc
 
processing
 
links
brian chia
kelvin zhao
ronald leong
 
 
Kinematics
 

Each segment should have a pivot point at one end which it can rotate. Any subsugments should be attached on the opposite end of the segment.

In Foundation Actionscript 3.0 Animation, they provided a very cool Segment Class to create segment, but for my example, i be just using rectangle. My main concern is to learn and not to reduplicate a chapter from the book.

Realise create kinematics isnt that diffcult, at least for this sample. What we need to do is to find the second segment position in relation to the first segment and position it according. Hmmm, doesnt this sound familiar, in fact we cover this in Coordinate Rotation v01.

Here, we can treat the first segment left end to be the center point, and the left end of the second segment to be rotating around the first segment left end. Of course, the radius from the center point is the first segment width, now we can apply the coordinate rotation to get the final position. Lastly to make thing look more natural, we need to rotate the second segment together with the first segment rotation.

One thing to note, declare a variable to store the inital segment width, do not use segment0._width when you are calculating the angle. This will result in an inaccurate result, once a movieclip is rotated, it width will also change according.

Rotation of the segments can be adjusted through the sliderbar.


// get segment width
var sl:Number=segment0._width;

// get segment rotation, range from -90 to 90
var sr0:Number=r0._x-rl0._x-90;
var sr1:Number=r1._x-rl1._x-90;

this.onEnterFrame=function():Void{

kinematic();

}

function kinematic():Void{

// return segment1 position relative to segment0
with(segment0){

_rotation=sr0;
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+sr1;

// get segment1 final position
segment1._x=xPos;
segment1._y=yPos;

}



suggestion

 
 
 
         
  © copyright 2007 THINKLUNATIC.    
Brian Chia Jonathan Ng