Parabolic Flight Path trouble

Jonnycakes

New Member
Reaction score
6
Hi, I am trying to make a spell where a unit throws an axe. There will be more to it later, but for now I am just trying to nail down the path of the axe. I want it to fly in a parabola, starting at a height of 80, reaching a max height of 440 (for now), and going 600 distance before the axe reaches its max height. This is all well and good, and I am fairly familiar with parabolas, but the axe just stays a constant height throughout its flight. Here is the code-any help?

EDIT: Solved. Made a stupid mistake with .d.

JASS:
scope axe initializer init

private struct axe
    unit caster
    unit missile
    real angle
    real x
    real y
    real h    //height
    real d    //distance
    
    private integer index
    private static axe array a
    private static integer count=0
    private static timer time
    
    private static method periodic takes nothing returns nothing
        local integer i=0
        local axe temp
        local location loc
        local real z

        loop
            exitwhen i==axe.count
            set temp=axe.a<i>
            set temp.d=temp.d+.04
            set loc=Location(temp.x+120*temp.d*Cos(temp.angle), temp.y+120*temp.d*Sin(temp.angle))
            call SetUnitPositionLoc(temp.missile, loc)
            set z=-(temp.d-600)*(temp.d-600)/1000+temp.h-GetLocationZ(loc)
            call BJDebugMsg(R2S(z))
            call SetUnitFlyHeight(temp.missile, z, 0)
            if z&lt;=0 then
                call temp.destroy()
                set i=i-1
            endif
            set i=i+1
        endloop
        set loc=null
    endmethod
    
    
    static method create takes unit u, real x, real y returns axe
        local axe t=axe.allocate()
        local location loc
        set t.x=GetUnitX(u)
        set t.y=GetUnitY(u)
        set loc=Location(t.x, t.y)
        set t.caster=u
        set t.angle=Atan2(y-t.y, x-t.x)
        set t.h=GetLocationZ(loc)+440
        set t.d=0
        set t.missile=CreateUnitAtLoc(GetOwningPlayer(u), &#039;h01R&#039;, loc, t.angle*bj_RADTODEG)
        //set t.sfx=AddSpecialEffectTarget(&quot;Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl&quot;, t.missile, &quot;sprite&quot;)
        set t.index=axe.count
        set axe.a[axe.count]=t
        set axe.count=axe.count+1
        if axe.count==1 then
            call TimerStart(time, .04, true, function axe.periodic)
        endif
        set loc=null
        return t
    endmethod
    
    
    method onDestroy takes nothing returns nothing
        //call DestroyEffect(.sfx)
        call RemoveUnit(.missile)
        set axe.count=axe.count-1
        set axe.a[axe.count].index=.index
        set axe.a[.index]=axe.a[axe.count]
        if axe.count==0 then
            call PauseTimer(time)
        endif
    endmethod
    
    
    private static method onInit takes nothing returns nothing
        set axe.time=CreateTimer()
    endmethod
    
endstruct


private function conditions takes nothing returns boolean
    return GetSpellAbilityId()==&#039;A028&#039;
endfunction


private function actions takes nothing returns nothing
    local axe temp=axe.create(GetTriggerUnit(), GetSpellTargetX(), GetSpellTargetY())
    call UnitAddAbility(temp.missile, &#039;Arav&#039;)
    call UnitRemoveAbility(temp.missile, &#039;Arav&#039;)
endfunction

//===========================================================================
private function init takes nothing returns nothing
    local trigger t=CreateTrigger()
    local integer x=0
    call TriggerAddAction(t, function actions)
    call TriggerAddCondition(t, Condition(function conditions))
    loop
        exitwhen x==12
        call TriggerRegisterPlayerUnitEvent(t, Player(x), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set x=x+1
    endloop
    set t=null
endfunction

endscope</i>
 

Jonnycakes

New Member
Reaction score
6
Okay...that really doesn't help me because...

1. I don't want the axe to start at a height of 0 (you don't throw things from your feet), I want it to start at a height of 80.

2. I already have worked out the math for the parabola equation I want (yes, I know the standard from parabola equation).

JASS:
set z=-(temp.d-600)*(temp.d-600)/1000+temp.h-GetLocationZ(loc)


The above code is what determines the new height.
For the standard form y=a(x-b)^2+c...

a=-1/1000
b=600
c=440(+Initial Terrain Height, but I will leave that out for now)

This means that the axe will start out at a height of 80...
x=0
y=80

(80)=-1/1000*(0-600)^2+440
80=-360000/1000+440
80=-360+440
80=80

and get to a height of 440 when x is 600:

(440)=-1/1000*(600-600)^2+440
440=-1/1000*0+440
440=440

etc.

The height of the axe never changes, though. It always stays at the "c" value (its max height). Can you please at least take a quick look at the code before criticizing me for not using the search function? Thanks ;)

EDIT: Solved. Stupid mistake involving what I used for my "x".
 

Jonnycakes

New Member
Reaction score
6
It compiles. If in a struct you create a static method create that takes nothing, you can define what arguments it takes. You can use this to save on lines of code/organize things better-everything that sets the initial values for a struct can be done in the create method.
 
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