Yeah, I solved it.
This is a pretty simple function(s), making the unit sway. The swaying isn't very smooth, I hope you don't mind.
This is a pretty simple function(s), making the unit sway. The swaying isn't very smooth, I hope you don't mind.
JASS:
library MakeUnitSway
private keyword Data
globals
private constant integer ENABLE_FLY=039;Amrf039;
// The Raven Form ability which enables flying
private constant real INTERVAL=0.03
// The timer interval. 0.03 is suggested, less can cause lag
private constant real DIVIDE=100
// d.z is divided with this
private constant real RATE=5000
// The "time" the unit is about getting from and to the ground/fly height
// Necessary globals
private Data array D
private integer N=0
private timer T=CreateTimer()
endglobals
//! WARNING WARNING WARNING WARNING WARNING WARNING WARNING
//! Real Snippet Code!
//! Don't touch if you don't know what you are doing!
//! WARNING WARNING WARNING WARNING WARNING WARNING WARNING
private struct Data
unit swayer
real z
real max
real min
real height
boolean hasReachedMax
endstruct
private function Callback takes nothing returns nothing
local Data d
local integer i=N
loop
exitwhen i<=0
set d=D<i>
if (d.z<d.min) then
set d.z=(d.z+(d.z/DIVIDE))
call SetUnitFlyHeight(d.swayer,d.z,0)
set d.hasReachedMax=false
elseif (d.z>d.max) then
set d.z=(d.z-(d.z/DIVIDE))
call SetUnitFlyHeight(d.swayer,d.z,0)
set d.hasReachedMax=true
elseif (d.z>d.min and d.hasReachedMax==false) then
set d.z=(d.z+(d.z/DIVIDE))
call SetUnitFlyHeight(d.swayer,d.z,0)
elseif (d.z>d.min) and (d.hasReachedMax==true) then
set d.z=(d.z-(d.z/DIVIDE))
call SetUnitFlyHeight(d.swayer,d.z,0)
endif
set i=i-1
endloop
endfunction
function MakeUnitSway takes unit whichUnit, real max, real min returns nothing
local Data d=Data.create()
set d.swayer=whichUnit
set d.height=GetUnitFlyHeight(whichUnit)
call UnitAddAbility(whichUnit,ENABLE_FLY)
call SetUnitFlyHeight(whichUnit,min,RATE)
set d.z=min-1
call UnitRemoveAbility(whichUnit,ENABLE_FLY)
set d.max=max
set d.min=min
set d.hasReachedMax=false
set N=N+1
set D[N]=d
if N==1 then
call TimerStart(T,INTERVAL,true,function Callback)
endif
endfunction
function StopUnitSway takes unit whichUnit returns nothing
local Data d
local integer i=N
loop
exitwhen i<=0
set d=D<i>
if d.swayer==null then
call BJDebugMsg("|cffff0000MakeUnitSway|r: invalid unit.")
return
endif
set D<i>=D[N]
set N=N-1
if N==0 then
call PauseTimer(T)
endif
call SetUnitFlyHeight(d.swayer,d.height,RATE)
call d.destroy()
set i=i-1
endloop
endfunction
private function TimedCallback takes nothing returns nothing
local Data d
local integer i=N
loop
exitwhen i<=0
set d=D<i>
call StopUnitSway(d.swayer)
set D<i>=D[N]
set N=N-1
set i=i-1
endloop
call DestroyTimer(GetExpiredTimer())
endfunction
function MakeUnitSwayTimed takes unit whichUnit, real max, real min, real duration returns nothing
local Data d=Data.create()
set d.swayer=whichUnit
set N=N+1
set D[N]=d
call MakeUnitSway(whichUnit,max,min)
call TimerStart(CreateTimer(),duration,false,function TimedCallback)
endfunction
endlibrary</i></i></i></i></i>