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.
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<=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;h01R039;, loc, t.angle*bj_RADTODEG)
//set t.sfx=AddSpecialEffectTarget("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl", t.missile, "sprite")
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;A028039;
endfunction
private function actions takes nothing returns nothing
local axe temp=axe.create(GetTriggerUnit(), GetSpellTargetX(), GetSpellTargetY())
call UnitAddAbility(temp.missile, 039;Arav039;)
call UnitRemoveAbility(temp.missile, 039;Arav039;)
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>