 A Flash Developer Resource Site

# Thread: Restricting angles in IK

1. ## Restricting angles in IK

Hi im currently working on a project involving IK. I have done basic IK (keeping distance), with help from Milan Toth's (MilGra) tutorial from gotoandplay.it, now im stuck at restricting angles. The tutorial is too complicated for me, i just want to know how to restric angles as simple as possible. Any help or nudge in the right direction would be greatly appreciated!!

*I know theres shorter and more optimized ways of writing IK, the below is just a test so i can easily understand whats doing what. thx agaiN!

_root.onEnterFrame = function() {

//JOIN POINT B WITH POINT A
d=30;
alpha2 = Math.atan2(_root.pt_B._y-_root.pt_A._y, _root.pt_B._x-_root.pt_A._x);
_root.pt_B._x = _root.pt_A._x+Math.cos(alpha2)*d;
_root.pt_B._y = _root.pt_A._y+Math.sin(alpha2)*d;
_root.pt_B._rotation = (Math.PI+alpha2)*180/Math.PI;

//JOINTS POINT C WITH POINT B
alpha3 = Math.atan2(_root.pt_C._y-_root.pt_B._y, _root.pt_C._x-_root.pt_B._x);
_root.pt_C._x = _root.pt_B._x+Math.cos(alpha3)*d;
_root.pt_C._y = _root.pt_B._y+Math.sin(alpha3)*d;
_root.pt_C._rotation = (Math.PI+alpha3)*180/Math.PI;
}

How do i restrict angle ABC? (Any degree you wish)
No one seems to know the answer in the games forum so i decided to post it in here.  Reply With Quote

2. PHP Code:
``` _root.onEnterFrame = function() {     //JOIN POINT B WITH POINT A     d = 100;     alpha2 = Math.atan2(_root.pt_B._y-_root.pt_A._y, _root.pt_B._x-_root.pt_A._x);     _root.pt_B._x = _root.pt_A._x+Math.cos(alpha2)*d;     _root.pt_B._y = _root.pt_A._y+Math.sin(alpha2)*d;     _root.pt_B._rotation = (Math.PI+alpha2)*180/Math.PI;     //JOINTS POINT C WITH POINT B     alpha3 = Math.atan2(_root.pt_C._y-_root.pt_B._y, _root.pt_C._x-_root.pt_B._x);     alpha3 = restrictAngle(alpha3, alpha2, Math.PI/3);     _root.pt_C._x = _root.pt_B._x+Math.cos(alpha3)*d;     _root.pt_C._y = _root.pt_B._y+Math.sin(alpha3)*d;     _root.pt_C._rotation = (Math.PI+alpha3)*180/Math.PI; }; function restrictAngle(alpha3, alpha2, range) {     var dAng = alpha3-alpha2;     var dAng = Math.atan2(Math.sin(dAng), Math.cos(dAng));     //a way to turn angle value between Math.PI to -Math.PI     //there should be a better way     if (dAng>range) {         return alpha2+range;     }     if (dAng<-range) {         return alpha2-range;     }     return alpha3; }  ```  Reply With Quote

3. hi! thx alot, that really helped me! Say, do you know a way to make angles fixed? non-moveable angles. thx!  Reply With Quote

4. alpha3=alpha2+someFixAngleValue;  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap 