• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

SetUnitFlyHeight issue

Status
Not open for further replies.
Level 3
Joined
Dec 30, 2011
Messages
54
Hi all,
I have a problem with SetUnitFlyHeight
JASS:
scope ArrowSystem initializer Init

globals
        private constant integer CROW = 'Amrf'
        private constant integer dummyID = 'h006'
        private constant integer SpellID = 'A002'
        private constant real FAR = 800.
        private constant real PERIOD = 0.01
        private constant real RANGE = 20
        private constant real SPEED = 8
endglobals

private struct ArrowSystemStruct
location target
unit caster
unit dummy
timer duration
boolean TimerBooOk

    method onDestroy takes nothing returns nothing
        set .target = null
        set .caster = null
        set .dummy  = null
        call ReleaseTimer(.duration)
    endmethod

    static method Move takes nothing returns nothing
    local ArrowSystemStruct data = GetTimerData(GetExpiredTimer())
    local unit caster = data.caster
    local location dummyLoc = GetUnitLoc(data.dummy)
    local real height = GetLocationZ(dummyLoc)
    local real flyHeight = GetUnitFlyHeight(data.dummy)
    local real angle = AngleBetweenPoints(dummyLoc, data.target)
    local location newLoc
    local location casterLoc = GetUnitLoc(data.caster)

    
    
    if (data.TimerBooOk == FALSE) then
    set newLoc = PolarProjectionBJ(dummyLoc,SPEED,angle)
    set flyHeight = (flyHeight - 0.001)
    

    
    call SetUnitFlyHeight(data.dummy, flyHeight - height, 0.00)
    call SetUnitPositionLocFacingBJ(data.dummy,newLoc,angle)
    
    
    
 
    
    endif
    
    if (DistanceBetweenPoints(dummyLoc, data.target)  < RANGE)and (data.TimerBooOk == FALSE) then
    set data.TimerBooOk = TRUE  
    
    endif                           
    
    if (data.TimerBooOk == TRUE) then
        call RemoveUnit(data.dummy)
        call data.destroy()
        
 
    endif 
    
    call RemoveLocation(dummyLoc)
    call RemoveLocation(GetUnitLoc(caster))
    call RemoveLocation(casterLoc)

    set caster = null
    set data = 0
    endmethod
    
endstruct   

private function Arrow_Actions takes nothing returns nothing
local ArrowSystemStruct data = ArrowSystemStruct.create()
local location casterLoc = GetUnitLoc(GetTriggerUnit())
local real height
local real face



set data.TimerBooOk = FALSE
set data.caster  = GetTriggerUnit()
set height = GetUnitFlyHeight(data.caster)
set face = GetUnitFacing(data.caster)
set data.target = PolarProjectionBJ(casterLoc, FAR, face)
set data.duration  = NewTimer()
set data.dummy = CreateUnitAtLoc(GetOwningPlayer(data.caster ), dummyID, PolarProjectionBJ(casterLoc,10, face), face)
call SetUnitFlyHeight(data.dummy, height + 80., 0.00)

call DisplayTextToForce( GetPlayersAll(), ( R2S(GetUnitFlyHeight(data.dummy) ) ) )
call DisplayTextToForce( GetPlayersAll(), ( R2S(GetUnitFlyHeight(data.caster) ) ) )
call SetUnitPathing(data.dummy, false)
call SetTimerData(data.duration ,data)
call TimerStart(data.duration , PERIOD, true, function ArrowSystemStruct.Move)

call RemoveLocation(casterLoc)
set data = 0
endfunction

function Arrow_Conditions takes nothing returns boolean
   if (GetSpellAbilityId() == SpellID) then
    call Arrow_Actions()
   endif
   
   return false
endfunction 


//===========================================================================
function Init takes nothing returns nothing
    local trigger t1 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t1, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t1, Condition( function Arrow_Conditions ) )
endfunction

endscope

In the function Arrow_Actions I create a unit (data.dummy) and then i change it's height to 80.0 + height of caster unit. (if caster is for example jumping it's height is not 0.0 so in this way it'll create the unit in front of him)
But nothing happens and the unit creates at height 0 even if the message shows the real height.
JASS:
call DisplayTextToForce( GetPlayersAll(), ( R2S(GetUnitFlyHeight(data.dummy) ) ) )

I've checked it with a simple trigger in order to see if it was a unit issue but it worked perfectly.
I'm confused :S
 
Level 3
Joined
Dec 30, 2011
Messages
54
JASS:
if UnitAddAbility(data.dummy,'Amrf') then
call UnitRemoveAbility(data.dummy,'Amrf')
endif
call SetUnitFlyHeight(data.dummy, height + 80., 0.00)

Like this? Because it doesn't work
Even if SetUnitFlyHeight is inside the if
 
Level 3
Joined
Dec 30, 2011
Messages
54
@Maker Here you are.
The trigger is inside the folder "Various" and it's called "Arrow System" ; the dummy I use is called "Dummy Arrow (h005)"

@mckill2009 Thanks for the hint. :)

Off - Topic : Also inside the map , in the Spawn folder, there's the trigger Wave which gave me some trouble ( see http://www.hiveworkshop.com/forums/triggers-scripts-269/spawn-system-issue-209908/#post2079876 )
If you could have a look also at that issue it would be great.
I just take advantage of the temporal attention :)
 

Attachments

  • Crystal Defenders.w3x
    300.6 KB · Views: 66
Level 29
Joined
Mar 10, 2009
Messages
5,016
- I've removed this call SetUnitFlyHeight(data.dummy, flyHeight - height, 0.00) and the height is fine...
JASS:
//coz your height is greater than flyHeight
//so your subtracting like >>> 80 - 256 = -176
local location dummyLoc = GetUnitLoc(data.dummy)
local real height = GetLocationZ(dummyLoc)
local real flyHeight = GetUnitFlyHeight(data.dummy)

- This set flyHeight = (flyHeight - 0.001) doesnt make sense since flyHeight is changing every time & 0.001 well, is as good as 0...
- You should set the angle at the "Arrow_Actions" function instead of declaring it every time...
- Use coordinates instead of locations or use a global location so that you dont need to call RemoveLocation(loc)...
 
Level 3
Joined
Dec 30, 2011
Messages
54
Thanks very much! My intention was to create an arrow that from a starting height would impact on the ground progressively.
So from a starting height called "h" for example in the method i have to decrease "h" every second checking also terrain conditions ( i mean : if height of unit is < of terrain level like : - | where - is the unit and | the terrain level ; i destroy it).
Is correct to set the trigger like this?

*I apologize for my english*
 
Status
Not open for further replies.
Top