Okay.... I've hit a snag with my Verlet angle constraint code. I've managed to get a decent minimum angle constraint writen up and working; however, it seems that a small problem comparing a theta using atan2 might prevent me from continuing for a while until I manage to solve the problem.

It seems that my code has a flaw and leaves off a quarter of the unit circle. In this quarter of the circle, Flash believes that it is part of the minimum constraint and solves it as such. Therefore, I believe that it may be a problem of bad mathematics that is at hand. The range is from 1-270 degrees, with another quarter circle 1-89.99999999.... I do use an absolute value, and sadly, that is a part of the problem.

If anything, I would like to stay away from the seemingly simple add a 90 degrees (that would modify the way the unit circle would look and would make my code seem confusing), and, while it seems a simple fix, it doesn't work.

Here's what I have so far (Please be nice to my code ) :

code:

var apL = this.apList;
var angL = this.angList;
var l0 = apL[0];
var l1 = apL[1];
var l2 = apL[2];
var MINA = angL[0];
var MAXA = angL[1];
var dx1 = l0.x - l1.x;
var dy1 = l0.y - l1.y;
var dx2 = l1.x - l2.x;
var dy2 = l1.y - l2.y;
var ang1 = Math.atan2(-dy1, dx1)*(180/Math.PI);
var ang2 = Math.atan2(dy2, dx2)*(180/Math.PI);
var ANG = Math.abs(ang1-ang2);
trace (ANG);
if (ANG < MINA){
ang2 += (MINA-ang2)-ang1;
ang2 /= 180/Math.PI;
l2.x = (l2.rList[0]*Math.cos(ang2)) + l1.x;
l2.y = (l2.rList[0]*Math.sin(ang2)) + l1.y;
} else if (ANG > MAXA) {
ang2 += (ang2-MAXA)-ang1;
ang2 /= 180/Math.PI;
l2.x = (l2.rList[0]*Math.cos(ang2)) + l1.x;
l2.y = (l2.rList[0]*Math.sin(ang2)) + l1.y;
}

This is run once every 9 milliseconds inside of a function. I did try appending Flade's Angular Constraint code into my own, but seemed to fail miserably.... Any help would be GREATLY appreciated.

EDIT:// Added the .fla I've been using to test this darned code. Hope this helps you more visual people.

Last edited by OpethRockr55; 01-07-2006 at 04:57 AM.

You have no idea how elated I am to present... the working angle constraint code!

code:

var apL = this.apList;
var angL = this.angList;
var l0 = apL[0];
var l1 = apL[1];
var l2 = apL[2];
var MINA = angL[0];
var MAXA = angL[1];
var dx1 = l0.x-l1.x;
var dy1 = l0.y-l1.y;
var dx2 = l2.x-l1.x;
var dy2 = l2.y-l1.y;
var ang1 = Math.atan2(dy1, dx1);
var ang2 = Math.atan2(dy2, dx2);
var ANG = (ang1-ang2)*(180/Math.PI);
if (ANG < 0) {
ANG += 360;
}
//trace(ANG);
if (ANG<MINA) {
var dAng = (MINA-ANG)/180/Math.PI;
l2.x = l2.rList[0]*Math.cos(ang2-dAng)+l1.x;
l2.y = l2.rList[0]*Math.sin(ang2-dAng)+l1.y;
}else if (ANG>MAXA) {
var dAng = (MAXA-ANG)/180/Math.PI;
l2.x = l2.rList[0]*Math.cos(ang2-dAng)+l1.x;
l2.y = l2.rList[0]*Math.sin(ang2-dAng)+l1.y;
}

*head explodes with ecstacy, releasing thousands of delicious swedish fish into the air.*

First off, let me apologize about not getting back to you on your other post.

The constrained limb glitch is caused because of two different things (if you're using this code). One: the center of the angle hasn't been corrected for the new placement of the points. There's code at the bottom for you. It's simply the average of the coordinates of the resolved angle minus the average of the old coordinates. Two: sometimes in collision with an object, the angle of the limb over-extends and causes a flip-flop. Let's say that a constricted arm collides with the ground and causes the hand to go up past the shoulder. This tells the angle code to go from 0-90 degrees to 270-360 degrees instantaneously and then the maximum angle 'if' statement is run instead of the minimum, causing massive jitter. I never found a workaround for that.

This is the code I finally came up with for my angular constraints. The variable OANG I left in just in case you wanted to attempt a workaround. I tried fixing it by doing something like: OANG set to 350 -> New angle is 10 -> if (OANG > 270 && ANG < 90) -> add 360 to new angle. That didn't work. So here it is: