Formula(s) Needed

Tinki3

Special Member
Reaction score
418
I am attempting to make a spell called "Multi Shockwave".

It is meant to send shockwaves casted by dummy units out from the caster's origin,
towards different angles, in a formation something like this:

untitledpv5.jpg


At level 1, it launches 2, so to be logical and to make the spell look "good",
the shockwaves should be the East-South-South, and the West-South-South.
(The one's closest to the South apart from the middle one).

Level 2 launches 3, so its formation should be the 3 closest to South.

Level 3 launches 4, the formation would be too hard to explain in words.

Level 4 launches 5, the formation would/should look exactly like the diagram.

Basically I need to have the formation of shockwaves more or less "centered",
and evenly-spread about the angle from the caster to the target location.

In saying this, if the angle between the caster and the target location was 90 dgrs,
I wouldn't want one shockwave shooting out towards 20 dgrs, and another shooting out 160 dgrs.

Here is my current JASS code for the spell:
JASS:
constant function Multi_Shockwave_Offset takes nothing returns real
    return 50.0
endfunction

constant function Multi_Shockwave_Amount takes integer lvl returns integer
    return 1 + lvl
endfunction

constant function Multi_Shockwave_Ability_ID takes nothing returns integer
    return 'A00J'
endfunction

constant function Multi_Shockwave_Dummy_Ability_ID takes nothing returns integer
    return 'A00K'
endfunction

constant function Multi_Shockwave_Temp_Dummy_ID takes nothing returns integer
    return 'h008'
endfunction

function Multi_Shockwave_Actions takes nothing returns nothing
    local unit u      = GetTriggerUnit()
    local location l  = GetSpellTargetLoc()
    local integer lvl = GetUnitAbilityLevel(u, Multi_Shockwave_Ability_ID())
    local integer amt = Multi_Shockwave_Amount(lvl)
    local integer c   = 1
    local real X1     = GetUnitX(u)
    local real Y1     = GetUnitY(u)
    local real X2     = GetLocationX(l)  
    local real Y2     = GetLocationY(l)  
    local real ang    = Atan2(Y2-Y1, X2-X1)/(amt + 1)
    local real X3
    local real Y3
    local unit d

    loop
        exitwhen c > amt
        set X3 = X1 + Multi_Shockwave_Offset() * Cos(ang * (c * 2))
        set Y3 = Y1 + Multi_Shockwave_Offset() * Sin(ang * (c * 2))     
        set d  = CreateUnit(GetOwningPlayer(u), Multi_Shockwave_Temp_Dummy_ID(), X1, Y1, bj_RADTODEG * (ang * (c * 2)))
        call UnitAddAbility(d, Multi_Shockwave_Dummy_Ability_ID())
        call IssuePointOrder(d, "shockwave", X3, Y3)
        set c  = c + 1   
    endloop

    call RemoveLocation(l)

    set u = null
    set l = null
    set d = null
endfunction

function Multi_Shockwave_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Multi_Shockwave_Ability_ID() 
endfunction

function InitTrig_Multi_Shockwave takes nothing returns nothing
    set gg_trg_Multi_Shockwave = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Multi_Shockwave, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Multi_Shockwave, Condition( function Multi_Shockwave_Conditions ) )
    call TriggerAddAction( gg_trg_Multi_Shockwave, function Multi_Shockwave_Actions )
endfunction

Want to know if it works?
Well, it does!

But not the way I desire it to.
As is, it evenly spreads the shockwaves from the angle given, but the formation of them
isn't the same if I cast at say 50 dgrs and 150 dgrs, or any angle to be exact.

For example, if I cast at roughly 180 dgrs, the shockwaves are widely spread. If I cast at roughly 0 dgrs, the shockwaves aren't spread at all.

This is because the angle between the points is used for the formula;
the closer its value is to 0, the smaller the space between each shockwave.

I could use an If-then-else statement to do this whole thing,
but that would be messy, and I am determined to get a formula working here.

If anyone would like to help me solve this problem, I'd be glad to hear from you.
 

Choppa

www.warcraft-gamers.po.gs
Reaction score
59
I don't know jass but from looking at it I can guess what it does but how does this return the angle?
Code:
local real ang    = Atan2(Y2-Y1, X2-X1)/(amt + 1)
That's if ang equals the angle the unit is facing... Is it?
 

Choppa

www.warcraft-gamers.po.gs
Reaction score
59
I just don't see why you'd need the level of the unit to get it position :confused:
Am I missing something?

I understand that "Atan2(Y2-Y1, X2-X1)" will return the angle between, hmm... if you minus the values (Y2-Y1) then that might give a totaly different value...

Let's say
Y2:70,
X2:60,
Y1:50,
X1:40,

Then "Atan2(Y2-Y1, X2-X1)" will be "Atan2(70-50, 60-40)" which will return the angle between (20, 20) which will equal 0 right? Unless that's not how Atan2 works... Tell me if i'm wrong.
 

Tinki3

Special Member
Reaction score
418
>I just don't see why you'd need the level of the unit to get it position

That has nothing to do with the actual angle between the 2 points.
Like I said, it's part of my inaccurate forumala which is used in the loop.

>Unless that's not how Atan2 works... Tell me if i'm wrong

Yep, you are (partly) :p

The Atan2 function returns the angle in radians.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> ang * (c * 2)

Whatever you think this is doing, it's probably not... :p


Point with polar offset: ... towards Casting direction
For i from 1 to Level - 1
- Point with polar offset: ... towards Casting direction + 15 * i
- Point with polar offset: ... towards Casting direction - 15 * i
 

Tinki3

Special Member
Reaction score
418
>In "nearly english"

Your right about that :p

Could you make it a little clearer?
I'm not sure what means what, or what goes with what.

Are those POs where I create the dummies at?
Or are they where I order them to cast shockwaves at?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Set PositionCaster = Position of Caster
Set Angle = Angle from PositionCasting to Target point of ability being cast

Unit - Create Dummy at PositionCaster
Set Point = PositionCaster offset by whatever towards Angle
Unit - Order Dummy to ...

For each Integer A from 1 to (Level of Ability being cast - 1)
- Unit - Create Dummy at PositionCaster
- Set Point = PositionCaster offset by whatever towards Angle + 15 * Integer A
- Unit - Order Dummy to ...
- Unit - Create Dummy at PositionCaster
- Set Point = PositionCaster offset by whatever towards Angle - 15 * Integer A
- Unit - Order Dummy to ...


Something like that I would guess.
Cleaned up for leaks, MUI and similar of course. Though I trust you don't need help with that part.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Would using an angle comparision between caster facing and target location be helpful here?

Your spell is always going to be centered on the angle of origin to target correct? (unless unit facing comes into it?) So would having (spell level variable number) of dummy points being set off the angle be a workable idea?

I don't know if that was clear. I'll try to explain what I'm thinking in this part. To do so I'll talk about something your not doing in your spell. Lets take it back a step. And lets use straight down cause it's easier to see. Lets assume straight down is 0 and you only have one target, just like a normal spell. Then move on from there. I'll also use points, but you can think in terms of coordinates. What I'm focusing on here is the thinking. You can convert later or as you read - suit yourself. See image below.

angles.jpg


Each of your dummy target points are going to be one of 9 points. The middle is always centered on the Angle of origin to spell target location. The two extremes are 45° and -45° (or whatever you set). The angle between the respective even and odd lines are always going to be 22.5°.

So, in words, this is what you'd do for your formula.

1 dummy target point. TDummyLoc=spell target
2 dummy target points. TDummy1Loc=spell target + 11.25. TDummy2Loc= - 11.25. (because half of 22.5 = 11.25)

3 dummy target point. TDummyLoc1=spell target. TDummyLoc2=spell target + 22.5°. TDummyLoc3=spell target - 22.5°.
etc and add another plus and negative onto the last angle.
etc and add another plus and negative onto the last angle.

Does that help any? Edit: lol beaten to the post by about er... 40 minutes lol.
 

emjlr3

Change can be a good thing
Reaction score
395
perhaps you have your answer, perhaps not

is the idea to have them more spread the farther away you cast? or a constant angle?

for the latter

id get anglebetweenpoints, where point 1 is the caster, and point 2 is the spelltargetloc

this is stored as a real, lets called it "ang"

now say we want 1 straight ahead down this angle, and 2 on either side....15 degrees away

id do something like
JASS:
integer i = 0
real ang = our angle gotten
real new_ang
real const_start = -30.
real cosnt_change = 15

loop
  exitwhen i>4
  set new_ang = ang-cons_start+(i*const_change)
  set i = i + 1
endloop


you can than pick a distance away you want to cast your ability, use your angle, and the polarprojection functions to grab a location out at that distance, at the correct angle
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top