13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with inverse kinematics<br />

The following pairs of properties <strong>en</strong>force these limits. The pairs consist of a Boolean value that indicates whether the<br />

movem<strong>en</strong>t is limited and an integer that specifies the limit:<br />

By default, all the Boolean values are set to false, so movem<strong>en</strong>t is not limited unless you explicitly set a Boolean value<br />

to true. To <strong>en</strong>force a limit, set the appropriate property to true and th<strong>en</strong> specify a value for the corresponding integer<br />

property. If you set the limit to a value without setting its corresponding Boolean property, the limit is ignored. In this<br />

case, the IK <strong>en</strong>gine continues to move the object until another limit or the target position of the IKMover is reached.<br />

In the following example, the maximum distance of the armature movem<strong>en</strong>t is set to 0.1 pixels per iteration. The<br />

maximum number of iterations for every movem<strong>en</strong>t is set to t<strong>en</strong>.<br />

ik.limitByDistance = true;<br />

ik.distanceLimit = 0.1;<br />

ik.limitByIteration = true;<br />

ik.iterationLimit = 10;<br />

Moving an IK Armature<br />

Flash Player 10 and later, Adobe AIR 1.5 and later, requires Flash CS4 or later<br />

The IKMover moves the axle inside the ev<strong>en</strong>t list<strong>en</strong>er for the wheel. On each <strong>en</strong>terFrame ev<strong>en</strong>t of the wheel, a new<br />

target position for the armature is calculated. Using its moveTo() method, the IKMover moves the tail joint to its<br />

target position or as far as it can within the constraints set by its limitByDistance, limitByIteration, and<br />

limitByTime properties.<br />

Wheel.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.ENTER_FRAME, frameFunc);<br />

function frameFunc(ev<strong>en</strong>t:Ev<strong>en</strong>t)<br />

{<br />

if (Wheel != null)<br />

{<br />

var mat:Matrix = Wheel.transform.matrix;<br />

var pt = new Point(90,0);<br />

pt = mat.transformPoint(pt);<br />

}<br />

Boolean property Integer property Limit set<br />

limitByDistance:Boolean distanceLimit:int Sets the maximum distance in pixels that the IK <strong>en</strong>gine moves for each<br />

iteration.<br />

limitByIteration:Boolean iterationLimit:int Sets the maximum number of iterations the IK <strong>en</strong>gine performs for each<br />

movem<strong>en</strong>t.<br />

limitByTime:Boolean timeLimit:int Sets the maximum time in milliseconds allotted to the IK <strong>en</strong>gine to<br />

perform the movem<strong>en</strong>t.<br />

}<br />

ik.moveTo(pt);<br />

Last updated 6/6/2012<br />

347

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!