PDA

View Full Version : Dead zones in my script...



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?

jman2050
03-02-2008, 06:21 PM
First off:


(Link->X - suckx) & (Link->Y - sucky);

I think what you meant to write was


Link->X -= suckx; Link->Y -= sucky;

More pressing though is that 1/tan is not *actually* an arctangent, that's a cotangent, a completely different operation. Arctan isn't actually implemented into the scripting engine yet, although you're welcome to try making an implementation by hand, although it'll probably be less annoying to just wait for a new beta with the atan function in it.

Linkus
03-02-2008, 07:07 PM
Yeah, I noticed my little error in the tangent there, but on the other part either way works fine.

We really need arctangent more than anything else, since scripts will become dependent on angles...

...Hmm... You said atan, and waiting for a new beta... You're not "suggesting" that the arctangent function will be added soon, are you? :D

Joe123
03-02-2008, 07:13 PM
The other part really shouldn't work fine, you're doing bitwise functions with that '&'.
I don't think you want to be.

Linkus
03-02-2008, 07:36 PM
How about this! I somehow fixed the problem by changing all my logic OR statements into AND statements. Here's the finished script:

import "std.zh"

ffc script vacuum{
void run(){
while(true){
int x = 128;
int y = 84;
float b; float p; float 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 = Tan(q / p); //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 > 0) && (b <= 90) && (p > 0) && (q > 0)){
Link->X -= suckx; Link->Y -= sucky;
}
if((b == 0) && (q > 0)){
Link->Y -= sucky;
}
if((b >= -90) && (b < 0) && (p < 0) && (q > 0)){
Link->X += suckx; Link->Y -= sucky;
}
if((b == 0) && (p < 0)){
Link->X += suckx;
}
if((b > 0) && (b <= 90) && (p < 0) && (q < 0)){
Link->X += suckx; Link->Y += sucky;
}
if((b == 0) && (q < 0)){
Link->Y += sucky;
}
if((b >= -90) && (b < 0) && (p > 0) && (q < 0)){
Link->X -= suckx; Link->Y += sucky;
}
//}
Waitframes(3); //controls suck rate
}
}
}

Enjoy!