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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Working with inverse kinematics<br />

Using Springs<br />

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

Inverse kinematics in Flash Professional CS5 supports bone spring. Bone spring can be set during authoring, and bone<br />

spring attributes can be added or modified at runtime. Spring is a property of a bone and its joints. It has two attributes:<br />

IKJoint.springStr<strong>en</strong>gth, which sets the amount of spring, and IKJoint.springDamping, which adds resistance<br />

to the str<strong>en</strong>gth value and changes the rate of decay of the spring.<br />

Spring str<strong>en</strong>gth is a perc<strong>en</strong>t value from the default 0 (completely rigid) to 100 (very loose and controlled by physics).<br />

Bones with spring react to the movem<strong>en</strong>t of their joint. If no other translation (rotation, x, or y) is <strong>en</strong>abled, the spring<br />

settings have no effect.<br />

Spring damping is a perc<strong>en</strong>t value from the default 0 (no resistance) to 100 (heavily damped). Damping changes the<br />

amount of time betwe<strong>en</strong> a bone’s initial movem<strong>en</strong>t and its return to a rest position.<br />

You can check to see if springs are <strong>en</strong>abled for an IKArmature object by checking its IKArmature.springsEnabled<br />

property. The other spring properties and methods belong to individual IKJoint objects. A joint can be <strong>en</strong>abled for<br />

angular rotation and translation along the x- and y-axes. You can position a rotational joint’s spring angle with<br />

IKJoint.setSpringAngle and a translational joint’s spring position with IKJoint.setSpringPt.<br />

This example selects a bone by name and id<strong>en</strong>tifies its tailJoint. The code tests the par<strong>en</strong>t armature to see if springs are<br />

<strong>en</strong>abled and th<strong>en</strong> sets spring properties for the joint.<br />

var arm:IKArmature = IKManager.getArmatureAt(0);<br />

var bone:IKBone = arm.getBoneByName("c");<br />

var joint:IKJoint = bone.tailJoint;<br />

if (arm.springsEnabled) {<br />

joint.springStr<strong>en</strong>gth = 50; //medium spring str<strong>en</strong>gth<br />

joint.springDamping = 10; //light damping resistance<br />

if (joint.hasSpringAngle) {<br />

joint.setSpringAngle(30); //set angle for rotational spring<br />

}<br />

}<br />

Using IK Ev<strong>en</strong>ts<br />

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

The IKEv<strong>en</strong>t class lets you create an ev<strong>en</strong>t object that contains information about IK Ev<strong>en</strong>ts. IKEv<strong>en</strong>t information<br />

describes motion that has terminated because the specified time, distance, or iteration limit was exceeded.<br />

The following code shows an ev<strong>en</strong>t list<strong>en</strong>er and handler for tracking time limit ev<strong>en</strong>ts. This ev<strong>en</strong>t handler reports on<br />

the time, distance, iteration count, and joint properties of an ev<strong>en</strong>t that fires wh<strong>en</strong> the time limit of the IKMover is<br />

exceeded.<br />

Last updated 6/6/2012<br />

348

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

Saved successfully!

Ooh no, something went wrong!