[Solved] Pitch Equation for missile trajectory!

Status
Not open for further replies.
Level 25
Joined
Feb 9, 2009
Messages
1,800
Need help getting started with a trigger please!

I have 3 missiles that I start off in the air (The Lich projectile in the image) that can either DESCEND or ASCEND If the target is a ground or air unit respectively, my problem is that my brain is full of rocks and I'm not math savvy, How can I make the missiles below match the green arrows instead of the (Current) red arrows when descending to the targeted (target) frame but still match flying targets?
NOTE: THE MISSILES ARE SPECIAL EFFECTS NOT UNITS
upload_2020-2-16_8-36-45.png

ezgif-6-67193d42e5e0.gif
Hugs and kisses, Peace love & understanding all that jazz.
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
You need to calculate the pitch angle between their current location and their target. You can do this with the Math - Arctangent (From Deltas) function (called Atan2 in JASS). It takes a y input (in this case the difference of fly heights: z_target - z_missile because it should be negative when going down) and an x input (XY distance from missile to target) and outputs the angle that is produced by that offset, which in this case would be the pitch angle you want.

There's the distance between points function which you can use, or to compute distance from xy coordinates (I know you often use coords with your sfx) you can use sqrt((xt-xm)*(xt-xm) + (yt-ym)*(yt-ym)).
 
Level 25
Joined
Feb 9, 2009
Messages
1,800
Thanks for joining in @Pyrogasm!

Pitch: (Radians((Atan2(((Position - Z of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) - (Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop])), CDnDs_ElMm_Distance[CDnDs_ElMm_Loop])))) Distance being from Missile to target naturally.
What am I missing here?
upload_2020-2-16_15-24-51.png


And on the matter of the equation for distance:
sqrt((xt-xm)*(xt-xm) + (yt-ym)*(yt-ym))

What are XT, XM, YT, & YM?
EDIT: Answered my own question ha! Very useful!
Missle & Target
 
Last edited:
Level 25
Joined
Feb 9, 2009
Messages
1,800
Set CDnDs_ElMm_Distance[CDnDs_ElMm_Loop] = (Distance between CDnDs_ElMm_Point[7] and CDnDs_ElMm_Point[8]) and I tried the equation you posted.

GUI special effects modifications to Yaw, Pitch, and Roll work with radians.
They rotate like throwing knifes if they are not converted to Radians.
This is Flippin hilarious:
ezgif-6-ffeb4cf3c8a0.gif
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
I swear when I read that function before my first reply it said "the angle returned is in radians"; you do need to convert like you're doing. Tested a bit, turns out positive pitch angle is in the -z direction (I guess that's an Euler angle thing?) so that's why it's wonky. To fix this you just need to reverse the order of subtraction for the first argument of Atan2.
 
Level 25
Joined
Feb 9, 2009
Messages
1,800
Works great on ground targets, unfortunately air targets are wonky...
ezgif-6-72692ac94543.gif

And now Vs Air
ezgif-6-4d4731e8b163.gif


This is how I calculate height, perhaps I'm doing it funny

Set CDnDs_ElMm_Height[CDnDs_ElMm_Loop] = ((Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop]) + ((((Position - Z of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) + ((Current flying height of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) + CDnDs_ElMm_Config_Arc[0])) - (Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop]))

(Arc is at 0.00)

EDIT: Additionally, is there a way to increase target's height destination for the missile? With the Height Variable just above, If I add to the Height it makes it arc! (Hence me adding an arc variable for those who want it) currently with no modifications the missile will hit the base of a target, I wouldn't mind pushing this up by to peasant chest height to generalize it unless there is some hidden bone handling.
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
:vw_sad: Holy moley I hate your variable names. I get it... but I hate them. Also the parenthesis doesn't add up there so I'm guessing that's not the whole line? It's missing 2 closing parenthesis. That line reduced for readability is:

Set Height[CDnDs_ElMm_Loop] = (Zeff + (Ztgt + (FLYtgt + Arc) - Zeff)

You're erroneously adding Zeff at the start, which cancels with the -Zeff at the end. This makes the function behave like the target point is always at 0. I would suggest you rewrite that line from scratch: (Ztgt + (FLYtgt + Arc)) - Zeff. Also arc isn't actually making it arc, you're just setting the angle of the effect as though it was higher than it actually is, which gives the effect of it turning more.

To increase height destination of the missile just add another configuration variable to the height computation: Ztgt = FLYtgt + offset + arc.
 
Level 25
Joined
Feb 9, 2009
Messages
1,800
Ah whoops!
Set CDnDs_ElMm_Height[CDnDs_ElMm_Loop] = ((Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop]) + ((((Position - Z of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) + ((Current flying height of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) + CDnDs_ElMm_Config_Arc[0])) - (Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop])) / (CDnDs_ElMm_Distance[CDnDs_ElMm_Loop] / CDnDs_ElMm_Speed[CDnDs_ElMm_Loop]))

And here are the results using the newer Height suggested:
Set CDnDs_ElMm_Height[CDnDs_ElMm_Loop] = (((Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop]) + ((Position - Z of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) + ((Current flying height of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) + CDnDs_ElMm_Config_Arc[0]))) - (Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop]))

ezgif-6-47538083c9c2.gif

Special effects are wonky... Thanks blizzard!
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
  • I see you're using begins casting to cancel the spell if no targets are found. This can be dicey because by spamming stop you can get the trigger to fire without actually casting the spell. I'd recommend splitting it into a begins casting and starts effect trigger.
  • The error message sound can only be played once at a time (not simultaneously) so it's possible that multiple people improperly attempting to cast the spell in rapid succession would cause the sound not to be played for anyone but the last player. Don't worry about it, but just so you know. (It's because the sound you are playing is actually a sound object that is created at map init and assigned to a sound variable)

  • Because the missiles are homing but their targets can move, you can't use a constant height offset. This is IMO a somewhat complicated problem to solve analytically (definitively?) and the best solution is to do it numerically. Tell the missile to use a descent speed that it anticipates will cause it to descend to the target at a rate that means it reaches the target when it hits the target. I think you've done this but for clarity with simpler variable names:

    Heff = effect height from terrain below it (set to some value upon 'start' of launch)
    Htgt = (flying) height of the target unit
    Hoff = vertical offset from the center of the target (to make impacts more direct)
    VZeff = vertical velocity of the effect
    dist = current xy distance from effect to target
    spe = xy speed of projectile
    Tperiod = timer period

    VZeff = (Htgt+Hoff - Heff)/(dist/spe)
    Heff = Heff + (VZeff*Tperiod)
 
Level 25
Joined
Feb 9, 2009
Messages
1,800
>Tell the missile to use a descent speed that it anticipates will cause it to descend to the target at a rate that means it reaches the target when it hits the target.
Please spoonfeed, I've been sitting on this problem for too long. ; ;

>I see you're using begins casting to cancel the spell if no targets are found. This can be dicey because by spamming stop you can get the trigger to fire without actually casting the spell. I'd recommend splitting it into a begins casting and starts effect trigger.
Ah, I thought about this, will do.

>I think you've done this but for clarity with simpler variable names:
was going for a Dnd spell pack but was advised to focus on this one, totally agree they are long winded.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Please spoonfeed, I've been sitting on this problem for too long. ; ;
Heff = effect height from terrain below it (set to some value upon 'start' of launch)
Htgt = (flying) height of the target unit
Hoff = vertical offset from the center of the target (to make impacts more direct)
VZeff = vertical velocity of the effect
dist = current xy distance from effect to target
spe = xy speed of projectile
Tperiod = timer period

VZeff = (Htgt+Hoff - Heff)/(dist/spe)
Heff = Heff + (VZeff*Tperiod)
Htgt+Hoff - Heff is how far down it has to travel from where it's currently at. dist/spe is how long it will currently take to reach the target (horizontally) if the target doesn't move any more. Therefore divide them and you get its presumed vertical velocity. Because you move every Tperiod you need to multiply by that factor when adding it to the height.
 
Level 25
Joined
Feb 9, 2009
Messages
1,800
Figured it out, Unit Z target only returns the ground the unit is standing on...
With this in mind, this was the fix it was just missing flying unit height and flipped around so it became Radian(Atan2((ZEff - (Ztar + FlyH)), Distance)))

Or in my long ass variable name: (Radians((Atan2(((Position - Z of CDnDs_ElMm_Effect[CDnDs_ElMm_Loop]) - ((Position - Z of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]) + (Current flying height of CDnDs_ElMm_Target[CDnDs_ElMm_Loop]))), CDnDs_ElMm_Distance[CDnDs_ElMm_Loop]))))


Thank you for joining me in mental gymnastics @Pyrogasm, more so you working and me watching to be honest.


Edit:
Height is supposed to be: zEff + (((zTar + (Fly + arc)) / (Distance / speed))
 
Last edited:
Status
Not open for further replies.
Top