Heh, I didn't see that either. :eyebrow:
I've had less than adequate results in the past with ZC trying to modify an objects screen position with decimal places though. (I stopped doing it altogether actually) Just thought I'd point that out.
Printable View
Heh, I didn't see that either. :eyebrow:
I've had less than adequate results in the past with ZC trying to modify an objects screen position with decimal places though. (I stopped doing it altogether actually) Just thought I'd point that out.
Well, I don't see any particular reason why it wouldn't work (assuming the engine doesn't truncate the positions), but if you're concerned about it:
Code:import "std.zh"
import "advmath.zh"
void moveTowards(ffc this, int x, int y, int speed) {
int angle = findAngle(this->X, this->Y, x, y);
float dx = Sin(angle) * speed;
float dy = Cos(angle) * speed;
this->X += Floor(dx);
this->Y += Floor(dx);
}
Cool I'll try that out... Btw, happy new year! :)
Takes a speed, and moves an object that doesn't have a Vx/Vy value at that speed. Currently works (well, it works mostly. Some speeds are a little out) for speeds from 0 to 2 (not inclusive).Code:while(true){
Link->X += move(this->Vx,counterx);
Link->Y += move(this->Vy,countery);
counterx = (counterx+1)%(100/factors100(Abs(this->Vx)));
countery = (countery+1)%(100/factors100(Abs(this->Vy)));
}
int move(int s,int c){
int as = Abs(s);
int ret;
if(as < 1){
if(c < as*100/factors100(as)) ret = 1;
else ret = 0;
}else if(as < 2){
if(c < (as-1)*100/factors100(as-1)) ret = 2;
else ret = 1;
}
if(s < 0) ret = -ret;
return ret;
}
int factors100(int s){
for(int i=50;i>0;i--) if((s*100)%i == 0) return i;
}
I'm sure it's not the best way, but I'm quite proud of it. Took me a while to think up.
Obviously you can't actually move an object by half a pixel, that just doesn't make sense.
Hang on, maybe I'll just, you know, test it.
EDIT: For cripes sake. I figured out why I was stupid.
I fixed a typo, and remembered that findAngle uses Radians, not Degrees. So, I switched Sin and Cos to RadianSin and RadianCos, and it works. It works without rounding off the decimal place, too.Code:import "advmath.zh"
void moveTowards(ffc this, int x, int y, int speed) {
int angle = findAngle(this->X, this->Y, x, y);
float dx = RadianSin(angle) * speed;
float dy = RadianCos(angle) * speed;
this->X += dx;
this->Y += dy;
}
ffc script followLink {
void run() {
while(true) {
moveTowards(this, Link->X, Link->Y, 1);
Waitframe();
}
}
}
And, since I tested it, I can now say that I guarantee this will work, or your money back.
Still doesn't work... When it has to go up, it goes down, and also it goes left when it has to go right(when it has to go up)... And I did tested your ffc script... :(
Hold on a minute...
Shouldn't the code be...
Changes I made are in bold.Code:import "advmath.zh"
void moveTowards(ffc this, int x, int y, int speed) {
int angle = findAngle(this->X, this->Y, x, y);
float dx = RadianCos(angle) * speed;
float dy = RadianSin(angle) * speed;
this->X += dx;
this->Y += dy;
}
ffc script followLink {
void run() {
while(true) {
moveTowards(this, Link->X, Link->Y, 1);
Waitframe();
}
}
}
It doesn't matter which way round you use them.
Well, it does matter, but either way, I tested my script, and it worked. So... I dunno what to say. Make sure you're passing a positive speed... that's the only way I can think of to make it go backwards...