dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Restricting angles in IK

  1. #1
    Spectator
    Join Date
    Oct 2002
    Location
    NA
    Posts
    72

    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.

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    PHP Code:
    _root.onEnterFrame = function() {
        
    //JOIN POINT B WITH POINT A
        
    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(alpha3alpha2Math.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(alpha3alpha2range) {
        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;


  3. #3
    Spectator
    Join Date
    Oct 2002
    Location
    NA
    Posts
    72
    hi! thx alot, that really helped me! Say, do you know a way to make angles fixed? non-moveable angles. thx!

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    alpha3=alpha2+someFixAngleValue;

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center