PDA

View Full Version : A better rotating FFC Script.



bigjoe
08-24-2007, 08:48 PM
I have a quest thats pretty much complete, which will be released whenever 2.5 comes out. It uses an old Z-ASM script by _L_ in order to create rotating fireballs.

Does anyone have or can anyone make a better FFC rotation system? I would like it to do the following.

1.Be able to rotate clockwise or counterclockwise.
2.Rotate at different speeds.

ShadowMancer
08-24-2007, 10:04 PM
Clockwise / counterclockwise should just be a matter of changeing a varible either - or + (Cosine if i remeber right..) as for speed that is kind of limited because of the way the circle is executed (I'm not a math expert, but I saw this explaned before if only I could find the thread again it had TONS of usefull info about programming movement, it was either AGN, Pure, of ZCU that I seen it but don't remember) Anyway I will think about this problem and see if I can think of another way to make a rotation besides the the standard programmers trick with sin and cos.

C-Dawg
08-25-2007, 12:31 AM
Parametric equation for a circle:

x = sin(n);
y = cos(n);

And you just increment n every time. If you want the dealie to move faster around the circle, you make n get bigger faster. Which you can do either by incrementing n a greater amount each time, or doing this:

x = sin(2*n);
y = cos(2*n);

If you want a bigger circle than the unit circle, you do this:

x = 2*sin(n);
y = 2*cos(n);

And if you want the circle off center (so it's not centered at 0,0), you do this:

x = 2+sin(n);
y = 2+cos(n);

Got it?

ShadowMancer
08-25-2007, 07:12 PM
Thanks C-Dawg, I am going to use these myself, Like I said not very good at math. Mostly I just look up info, although lately I have been compileing a list of useful math for programming. I do have one question, (not exactly releated to this thread sorry) but do you know the equation I would need for a bounce/reflect effect (Im looking for pong but it vanished)

DarkDragon
08-25-2007, 07:53 PM
The basic rule for reflections is "angle of incidence = angle of reflection." That is, if you draw a line representing your surface, and you draw a line representing an object's inbound trajectory, the angle made by the surface and the inbound trajectory is equal to the angle that will be made by the surface and the outbound trajectory.

For horizontal and vertical surfaces the equations are particularly easy. Here we assume vx and vy are the velocities of the inbound object.

Hitting a vertical wall:
vx_new = - vx;
vy_new = vy;

Hitting a horizontal wall:
vx_new = vx;
vy_new = -vy;

ShadowMancer
08-25-2007, 08:17 PM
Thanks DD I'll add this to my database of programming equations

C-Dawg
08-27-2007, 12:04 PM
Actually, you might want to use a "quasi-realistic" reflection rule. Remember the Diamond weapon from the Castlevania series? In Simon's Quest, it shot out straight, but would bounce up at an angle once it hit a wall, and reflect realistically from there. It would be boring for it to just bounce straight back the way it came.

But another solution is the diamond in Symphony of the Night. There, it always used true reflection, but it shot out of Alucard's hand at a downward angle so it was ready to start bouncing.

Just something to think about when you're making a bouncy thing.

And, yea, your best friend in ZScripting is your eighth-grade math textbook on cartiesian coordinates and trig. It took me a few months to brush up on the basic equations for lines and parabolas and so forth.

ShadowMancer
08-27-2007, 02:02 PM
I was thinking of baseing my boune from the center of the FFC to the center of the object it is bounceing off of (16X16 tile) I think this would cause a quasi-real effect in that if the ffc hits off center it will bounce accordingly. I need to test this however (Im into so many little projects right now) The effect is going to be used for a 'reflect enemy magic' script that was requested, Just need to play with the math abit and see what it does.



And, yea, your best friend in ZScripting is your eighth-grade math textbook on cartiesian coordinates and trig. It took me a few months to brush up on the basic equations for lines and para Very true, time to brush up again myself been awile since I actuall used this stuff :p

bigjoe
08-31-2007, 01:34 AM
Got it?

I understand it, I just dont quite know how to syntax it, which was why I posted in the requests forum. I guess I'll have to admit that I'm not a very good scripter.

C-Dawg
08-31-2007, 10:35 AM
Well like this. Inside your while loop:

this_ffc->X = sin(y);
this_ffc->Y = cos(y);

y++;


Thats all you really need. Of course, to center it on something:

this_ffc->X = other_ffc->X + sin(y);
this_ffc->Y = other_ffc->Y + cos(y);

y++;

That better?

beefster09
09-02-2007, 04:40 PM
Interesting! When I do my trig calculations, I get sin for y coords and cos for x coords. I hope it isn't flipped in ZScript.

C-Dawg
09-02-2007, 06:44 PM
That may be, beefster, but you'll find there is no difference in swapping X and Y if you're moving in a circle.

Gleeok
10-06-2007, 03:03 AM
I'm having problems reproducing a patra type circle. So how would I go about producing 8 rotating ffc's to the patra effect?

Gleeok
11-22-2007, 09:48 AM
Well like this. Inside your while loop:

this_ffc->X = sin(y);
this_ffc->Y = cos(y);

y++;





I have no idea to how that would work. I tried about 20 variations of sin and cos trying to get a fireball to move in a circular pattern and nada. Beefster, could you perhaps post the fireball script, or maybe just bludgeon me to death with a college level math book, that would also work.

Gleeok not like trig.


Here's the last 2 monumental failures. And they are obviously initialized by another script...supposedly.


ffc script ffc_wobble{

void run(){

int wobble = 0;

while(true){

if(this->Y > 168||this->Y < 0||this->X > 248||this->X < 0){
this->X = 0; this->Y = 0; this->Vx = 0; this->Vy = 0;
this->Data = 1;
}
this->X = Sin(wobble);
this->Y = Cos(wobble);

wobble++;
Waitframe();
}
}
}

ffc script ffc_wobble2{

void run(){

int wobble = 0;

while(true){


if(this->Y > 168||this->Y < 0||this->X > 248||this->X < 0){
this->X = 0; this->Y = 0; this->Vx = 0; this->Vy = 0;
this->Data = 1;
}
if(this->Vx != 0 || this->Vy != 0){

int x = this->Vx; int y = this->Vy;

this->Vx = x *Sin(wobble);
this->Vy = y *Cos(wobble);

wobble++;
}
Waitframe();
}
}
}