Linkus
03-02-2008, 05:07 PM
So yeah, I've been trying to make a vacuum script that sucks Link "into" a FFC in any direction through arc tangents, yet I've got horrendous dead zones within the 45 to 89 degree and -45 to -89 degree areas. (90 and -90 work, of course.)
I've tried a few ideas to work around this, but so far nothing. Here's what i';ve got on the code;
import "std.zh"
ffc script vacuum{
void run(){
while(true){
int x = 128;
int y = 84;
int b; int c; int p; int q;
int suckx = 1;
int sucky = 1; //suction pawer
//int r = n; //r is radius in pixels
this->X = x; this->Y = y;
p = Link->X - x;
q = Link->Y - y;
b = Pow(Tan(q / p), -1); //checks angle between Link and FFC
//if(r <= (sqrt((p * p) + (q * q)))
//^distance formula to check if Link is in range.
//remove "//' at the beginning of lines 7, 11, and
//42 and replace "n" with length of radius.
if((b == 0) && (p > 0)){
Link->X -= suckx;
}
if((b > -90) || (b <= 90) && (p > 0) && (q > 0)){
(Link->X - suckx) & (Link->Y - sucky);
}
if((b == 0) && (q > 0)){
Link->Y -= sucky;
}
if((b >= -90) || (b <= 90) && (p < 0) && (q > 0)){
(Link->X + suckx) & (Link->Y - sucky);
}
if((b == 0) && (p < 0)){
Link->X += suckx;
}
if((b > -90) || (b <= 90) && (p < 0) && (q < 0)){
(Link->X + suckx) & (Link->Y + sucky);
}
if((b == 0) && (q < 0)){
Link->Y += sucky;
}
if((b >= -90) || (b <= 90) && (p > 0) && (q < 0)){
(Link->X - suckx) & (Link->Y + sucky);
}
//}
Waitframes(3); //controls suck rate
}
}
}
I try to keep the code clean and straightforward. :tongue:
Also, don't forget to have "Diagonal Movement" checked in order to make it fully functional.
Update: Looking further into this, b = Pow(Tan(q / p), -1) is not the same as arctan. Therefore, is arctan possible, or is a command for arctan even availible?
I've tried a few ideas to work around this, but so far nothing. Here's what i';ve got on the code;
import "std.zh"
ffc script vacuum{
void run(){
while(true){
int x = 128;
int y = 84;
int b; int c; int p; int q;
int suckx = 1;
int sucky = 1; //suction pawer
//int r = n; //r is radius in pixels
this->X = x; this->Y = y;
p = Link->X - x;
q = Link->Y - y;
b = Pow(Tan(q / p), -1); //checks angle between Link and FFC
//if(r <= (sqrt((p * p) + (q * q)))
//^distance formula to check if Link is in range.
//remove "//' at the beginning of lines 7, 11, and
//42 and replace "n" with length of radius.
if((b == 0) && (p > 0)){
Link->X -= suckx;
}
if((b > -90) || (b <= 90) && (p > 0) && (q > 0)){
(Link->X - suckx) & (Link->Y - sucky);
}
if((b == 0) && (q > 0)){
Link->Y -= sucky;
}
if((b >= -90) || (b <= 90) && (p < 0) && (q > 0)){
(Link->X + suckx) & (Link->Y - sucky);
}
if((b == 0) && (p < 0)){
Link->X += suckx;
}
if((b > -90) || (b <= 90) && (p < 0) && (q < 0)){
(Link->X + suckx) & (Link->Y + sucky);
}
if((b == 0) && (q < 0)){
Link->Y += sucky;
}
if((b >= -90) || (b <= 90) && (p > 0) && (q < 0)){
(Link->X - suckx) & (Link->Y + sucky);
}
//}
Waitframes(3); //controls suck rate
}
}
}
I try to keep the code clean and straightforward. :tongue:
Also, don't forget to have "Diagonal Movement" checked in order to make it fully functional.
Update: Looking further into this, b = Pow(Tan(q / p), -1) is not the same as arctan. Therefore, is arctan possible, or is a command for arctan even availible?