Jump to content

Photo

Outward spiral/curved movement for projectiles


  • Please log in to reply
3 replies to this topic

#1 CastChaos

CastChaos

    Deified

  • Members

Posted 28 August 2015 - 04:55 PM

While trying to make attacks for an autoghosted boss, I found out the way to make many good things, but one is befuddling me to no extent.

 

 

I'd like the boss to shoot the projectiles in different directions not straight, rather in a curved path, like here:

http://www.shutterst...nline=256440580

 

 

I thought this would do it:

fireball[0] = FireEWeapon(ghost->Weapon, ghost->X, ghost->Y, 45, 10, ghost->WeaponDamage, SPRITE_BALL_ENERGY2, 0, EWF_UNBLOCKABLE);
fireball[1] = FireEWeapon(ghost->Weapon, ghost->X, ghost->Y, 135, 10, ghost->WeaponDamage, SPRITE_BALL_ENERGY2, 0, EWF_UNBLOCKABLE);
 fireball[2] = FireEWeapon(ghost->Weapon, ghost->X, ghost->Y, 225, 10, ghost->WeaponDamage, SPRITE_BALL_ENERGY2, 0, EWF_UNBLOCKABLE);
 fireball[3] = FireEWeapon(ghost->Weapon, ghost->X, ghost->Y, 315, 10, ghost->WeaponDamage, SPRITE_BALL_ENERGY2, 0, EWF_UNBLOCKABLE);
 SetEWeaponMovement(fireball[0], EWM_SINE_WAVE, 80, 120);
 SetEWeaponMovement(fireball[1], EWM_SINE_WAVE, 80, 120);
 SetEWeaponMovement(fireball[2], EWM_SINE_WAVE, 80, 120);
 SetEWeaponMovement(fireball[3], EWM_SINE_WAVE, 80, 120);

 

Since 10 amplitude and 10 frequency made the projectiles resonate a bit and move very slow (fun, and plausible with limited projectile time, but is not what I'm looking for here), I thought an amplitude of 80 would make the curve return to the x axis after 80 pixels after a 120 pixels of deviation at its tangent mean. INSTEAD the same vibration happened, except now the projectiles also kept vanishing each 2nd frame. WHAT?!

I also was trying the "drift" movement, but it made just one sprite instead of 4 and made it thunder through the screen from left to right (even though the startpoint is clearly the boss...). Acceleration type was made it just flash up here and there on the screen almost randomly. It's true I accidentally had 0 as step speed in both cases.

 

 

 

So, how to make that curved path?

I know the enemy of the week entry, Daygleam (from where I copy kinda all my projectile shooting code lines) has it right, but there the path is drawn by creating a new eweapon at each pixel of the curved path... I want one single eweapon to travel through that curved path.

 

 

 

Now...

I generally know what trigonometry is...

Sinus is wavy, cosinus is wavy pushed a bit away, tangent is the this: |- and produces a strange matrix.

But I just can't know and absolutely don't see where to use which. WHY is it that when drawing something around a target in a circle, the X coordinate has a sinus-ed value added, while the Y has cosinus-ed one added.

Is there a place from where I could learn these ZC relations? For example "To have something keep circling the target, add x-cos(x) to the x and y-tangent(y)*0.06+56.386 every frame. The mathematical explanation is..."


  • Avaro likes this

#2 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 28 August 2015 - 05:56 PM

I think your projectiles might be vanishing because the second argument to the ghost sine eweapon movement is how many degrees per frame it moves through, and 120 is crazy high. That means it will travel along the full wave path 20 times per second. You see a similar thing if you try to set enemy step speed extremely high, where the enemy seems to poof out existence frequently. A number like 6 would be more reasonable. The drift and veer problems might be a similar issue, where you set the second argument too high. It's also worth noting that drift and veer take one of the eight direction constants as the first argument, not an angle.

 

If you want eweapons to move independently according to some pattern, you'll have to store info for each individual weapon. The best place to do this is in the eweapon's Misc[] array. Indexes 0 through 2 are not used by ghost.zh, and should be free for this purpose. To have something circle a target, you can use these equations.

 

ewpn->X = target_x + radius * Cos(angle);
ewpn->Y = target_y + radius * Sin(angle);

 

In order to have something spiral, you just need the radius to change over time. A simple way to do that is this.

 

ewpn->X = target_x + t * Cos(t);
ewpn->Y = target_y + t * Sin(t);
t++;

 

But you don't have to tie the angle and radius together like that. You can change them independently if you want. Since you don't want every eweapon to be at the same angle and radius, this is where the Misc[] array comes in.

 

ewpn->X = target_x + ewpn->Misc[0] * Cos(ewpn->Misc[1]);
ewpn->Y = target_y + ewpn->Misc[1] * Sin(ewpn->Misc[1]);
ewpn->Misc[0] += 0.5;
ewpn->Misc[1] += 3;

 

You use a for loop to run this code on every eweapon on the screen, so it properly positions all of them. You can restrict it to a certain type of weapon, of course, so not all of them will behave this way. You could restrict the spiraling behavior to EW_SCRIPT5, for example.

 

As for why you use these equations for circles, you can see it by inscribing right triangles inside a circle centered at 0,0. The hypotenuse is the radial line, and two legs are drawn from the edge of the circle toward the x and y axes. When you know how sine and cosine are defined, you can see why those equations give the x, y on the circle for a given angle.



#3 CastChaos

CastChaos

    Deified

  • Members

Posted 29 August 2015 - 04:09 AM

*turns to camera from the screen*

Of course!

 

The circle around the 45° based triangle, it's the guideline!

Thank you!

 

Using the sine movement, I could make something I wanted by setting the frequency to 1, but increasing the weapon speed to a whopping 60. So next time I want something to be curved, I use that incremental "cos, sin" method you showed.

 

 

Now all I don't understand why don't the 4 eweapons are starting off evenly. I have the angles at "45, 135, 225, 315" which are 4 cardinal points, 90 degrees apart, yet now 3 of my projectiles are shot evenly (120 degress apart) and the 4th is close to one of them (about 10 degrees away). Maybe I need it not as 45 but as DegtoRad(45)...?



#4 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 29 August 2015 - 05:09 AM

If those four are being shot with FireEWeapon using the sine pattern, then yes, the angles do need to be in radians. ZScript likes to shift between degrees and radians for different functions for mysterious reasons.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users