• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Big Math Problem

Status
Not open for further replies.
Level 17
Joined
Sep 8, 2007
Messages
994
Hey Guys,


I tried to figure it out already but well, it didn't work quite well...

I need a formula to spin missiles around a unit. However, I don't want them to spin them "flat" on the ground. As you can see in the attached picture, the missile (black spot) should spin around the unit (stick figure) like that ...
(damn I miss all words I need to explain what I need xD) I hope you can understand what I mean.

What I need, is the x, y, and z coordinate.

Replies will be granted with rep.

(Ignore the small spots on the left side, blame paint and MS Picture Manager for the quality)
 

Attachments

  • Pic.jpg
    Pic.jpg
    17.6 KB · Views: 478
Level 8
Joined
Feb 15, 2009
Messages
463
no makes no sense coz when u move diagonal then the y value will bug around so it will look odd again
thats a harder prob then thinking of in beginnning

maybe use your mathematics formulas book (from school) to search for such mathematic functions(3dimensional)(but if you have share plz it is interresting me 2)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Pah, just handle the X and Y part separatly from the Z using trig. Aka you are after breaking the problem down into 2 parts which you use common input to get syncronized output.

You have your radius, so handle the rotation of the missle as an angle and input it into a trig function to get the realtive offset, which you multiply with radius.

Eg Sin(a)*r will give you the Z offset for the missle realitive to the height of the unit.
Sin(0)*r will output 0, which will be flat on the same height as the unit.
Sin(90 or pi/2)*r will output r, which is the radius of the circle so will be the radius above the unit.
Sin(270 or 3pi/2)*r will output -r, which is the negative radius of the circle so will be the radius below the unit.

Your end formula would be.
uZ+Sin(a)*r
where uZ is the unit height of the target and r is the circle radius.

This is your accurate Z rotation, if you do this alone you will notice that it gains and loses height like you want it to, however it is not the X and Y rotation so it would look strange.

For the X and Y, the same base method is used but with an extra value and 2 stages to end up with 2 separate outputs, one for X and other for Y.
As this is the other demension on out 2D rotationary circle, you need to use the other trig function.

Cos(a)*r will give you the offset for the X and Y axis to use for a realistic circle.
I will not explain this as I am sure you understand the difference that Cos and Sin have.

Now that you have your offset distance, it is time you wrap it into the X and Y world, but to firstly do that we need to introduce another rorationary angle, the angle of the circle as far as the X and Y plain goes (b).

This is basically the same as every polar offset opperation you do, but for the distance you use your Cos(a)*r.

The end results in
X = uX + Cos(b) * Cos(a) * r
Y = uY + Sin(b) * Cos(a) * r

Now to recap on all 3 formula.
X = uX + Cos(b) * Cos(a) * r
Y = uY + Sin(b) * Cos(a) * r
Z = uZ + Sin(a) * r

For your manipulating and interfacing variables for the formula.
r = the radius of the circle you want produced and should be constant between all 3 formula for a perfect circle.
a = the angle of the missle on its X and Y against Z rotation. You increase this each update to make the missle move in a circle. Faster/greater the increase, the faster the missle moves.
b = the x and y rotation of the circle realitive to the unit. 0 will result in the missle rotation circle always being paralel to the Y axis lines running fom left to right on the screen. For best results base this on the angle of the caster from target unit.

For your input variables.
uX/Y/Z = the X/Y/Z of the unit at the time of each update you preform.

Remeber that WC3 trig functions work in radians not degrees when manipulating a and b variables.
Also remember that as you will be using fly height for unit Z, you need to factor in the terrain heing for best results or hills will cause your perfect circle to destort.
Also I am not too sure if units can go below the terrain height, so your missle may end up scraping the floor.

On examination, this is prety much the same as the one Element of Water used. However my formulas listed could probably be optimized.
 
Level 17
Joined
Sep 8, 2007
Messages
994
Hm, what Element of Water used what nearly what I needed, but though not what I needed exactly.

Show.png
Here is a pic of what I need. Imagine this all being 3D.
You see, Element of Water fixes his missiles on the green line, though I need them to be fixed on the red line.
So, Dr Super Good, if your formulas are the same as Element of Water's, then it isn't exactly what I was looking for, too :p

The missiles must not move like a sphere at Element of Water's system but just stay at the casters position and spin vertical.
Thanks for your help, +rep!
 
eh, i just love Math

ok, here the code of the small testmap i posted above

JASS:
scope spin initializer init

globals
    real radians = 0 // bla system variable 
    real radius  = 75 // radius
    real height  = 75 // height ~.~
    real speed = 0.15 // speed
    real xoffset = 16 // an x offset due the coodinates seem to be attached at the left side of the unit (its half the collision now)
    real angleoffset = 90  // turned the spin, without it spins from behind to foreward
    unit target  // test0r
    unit dummy  //test0r
endglobals

function action takes nothing returns nothing
    local real angle = GetUnitFacing(target) + angleoffset
    set radians = ModuloReal(radians +speed,2*bj_PI)
    call SetUnitX(dummy,GetUnitX(target) + xoffset + Cos(angle*bj_PI/180.0) * Sin(radians) * radius)
    call SetUnitY(dummy,GetUnitY(target) + Sin(angle*bj_PI/180.0) * Sin(radians) * radius)
    call SetUnitFlyHeight(dummy,height   + Cos(radians) * radius,0)
endfunction

//===========================================================================
function init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    set target = gg_unit_Hpal_0000
    set dummy = gg_unit_hfoo_0001
    call TriggerRegisterTimerEventPeriodic( t, 0.03 )
    call TriggerAddAction( t, function action )
endfunction

endscope
 
Level 17
Joined
Sep 8, 2007
Messages
994
Thats not what he is after, he even said so...

He wants the unit to spin not move in circles.

For this he will have to use a dumy model as they are the only things that support Z rotation via triggers.

Well, yes :p what he made there was exactly what I needed.

Thanks JohnNny!!! You will be my math-problem-solution in the future xD
 
Level 17
Joined
Sep 8, 2007
Messages
994
But that is exactly what I posted.... Make your mind up damn it...

Did you want them to spin at the same point, or go in an orbiting circle around a point or unit?

As I already said - vertical, locked on a unit. JohnNny made it exactly how I meant.

I already gave you the exact calculations on the chat...

Yes, I was about to try those when JohnNny gave a reply with a corresponding map ... I just tried it first! :eek:
Though, thanks to you both, too.
 
Status
Not open for further replies.
Top