• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] I need formula for linear projectile moving

Status
Not open for further replies.
Level 5
Joined
Feb 6, 2008
Messages
134
I need help with formula for linear porjectile moving.

attachment.php


Projectile fly height is 0 and need to be setted every 0.02 second based on Z axis.
 

Attachments

  • Missle linear moving formula.JPG
    Missle linear moving formula.JPG
    145.2 KB · Views: 348
Level 8
Joined
Apr 30, 2009
Messages
338
I have no idea how the code would look but you would have to do this somehow:

terrain height at launch: h0
projectile height at launch: p0
time in flight: t
terrain height at time t: h1
projectile height at time t: p1

p1 = p0 + (h0 - h1)

if p1 < h1, then destroy projectile
 
Level 11
Joined
Apr 6, 2008
Messages
760
real Height, The height of the projectile
location Loc, The location of the projectile

Height-GetLocationZ(Loc) Set the flying height of the dummy like this everytime you move it

EDIT:

or as TriggerHappy said :D

JASS:
Height-GetUnitZ('Unit')
 
Level 5
Joined
Feb 6, 2008
Messages
134
First formula don't working


JASS:
function Projectile_Set_Conditions takes nothing returns boolean
    if ( GetUnitTypeId(GetAttacker()) == 'H00D'  ) then
        return true
    endif
    return false
endfunction


function Projectile_Set_Actions takes nothing returns nothing
local unit u = GetAttacker()
local unit u2 = GetTriggerUnit()
local unit lcu
local location la = GetUnitLoc(u)
local location lt = GetUnitLoc(u2)
local location l2 = PolarProjectionBJ(la, 30.00, AngleBetweenPoints (la, lt))

    call CreateNUnitsAtLocFacingLocBJ( 1, 'h007', GetOwningPlayer(u), l2, lt )
    set lcu = GetLastCreatedUnit()
    call RemoveLocation(la)
    call RemoveLocation(lt)
    call RemoveLocation(l2)
    call UnitApplyTimedLife(lcu, 'BHwe', GetRandomReal(0.33, 4.00))
    call GroupAddUnitSimple( lcu, udg_projectile_group )

    call SaveReal( udg_hastable_projectile, GetHandleId(lcu), 0 , 24 )   //25 is missle speed.
    call SaveInteger( udg_hastable_projectile, GetHandleId(lcu), 1, 30 )   //30 is missle damage
    call SaveReal( udg_hastable_projectile, GetHandleId(lcu), 2, 50 )   //50 is minimum missle range to hit unit
    call SaveStr( udg_hastable_projectile, GetHandleId(lcu), 3, "" )   //"" is Impact effect path.
    call SaveInteger( udg_hastable_projectile, GetHandleId(lcu), 4, (GetTerrainVarianceBJ(l2)) )   //Terrain height
    call SaveInteger( udg_hastable_projectile, GetHandleId(lcu), 5, 90 )   // Projectile Height

    call EnableTrigger( gg_trg_Projectile_Engine )

set u = null
set u2 = null
set lcu = null
set la = null
set lt = null
set l2 = null
endfunction

// INIT
function InitTrig_Projectile_Set takes nothing returns nothing
    set gg_trg_Projectile_Set = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Projectile_Set, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Projectile_Set, Condition( function Projectile_Set_Conditions ) )
    call TriggerAddAction( gg_trg_Projectile_Set, function Projectile_Set_Actions )
endfunction


JASS:
function Projectile_Engine_Functions takes nothing returns nothing
local unit u = GetEnumUnit()
local real r = LoadReal(udg_hastable_projectile, GetHandleId(u), 0)
local integer i = LoadInteger(udg_hastable_projectile, GetHandleId(u), 1)
local integer i2 = LoadInteger(udg_hastable_projectile, GetHandleId(u), 2)      
local location l = GetUnitLoc(u)
local location l2 = PolarProjectionBJ(l, r, GetUnitFacing(u))
local real hp = GetUnitState(u, UNIT_STATE_LIFE)
local integer h0 = LoadInteger(udg_hastable_projectile, GetHandleId(u), 4)
local integer p0 = LoadInteger(udg_hastable_projectile, GetHandleId(u), 5)
local integer h1 = (GetTerrainVarianceBJ(l2))
local integer p1 = p0 + (h0 - h1)


    if not( p1 < h1 ) then
        call SetUnitPositionLoc( u, l2 )
        call SetUnitFlyHeight(u, p1, 0)

    else
        call GroupRemoveUnitSimple( u, udg_projectile_group )
        call FlushChildHashtable( udg_hastable_projectile, GetHandleId(u) )
    endif

call RemoveLocation(l)
call RemoveLocation(l2)
set u = null
set l = null
set l2 = null
endfunction


function Projectile_Engine_Actions takes nothing returns nothing

    if ( ( CountUnitsInGroup(udg_projectile_group) > 0 ) ) then
        call ForGroup( udg_projectile_group, function Projectile_Engine_Functions )
    else
        call DisableTrigger( GetTriggeringTrigger() )
    endif

endfunction

// INIT
function InitTrig_Projectile_Engine takes nothing returns nothing
    set gg_trg_Projectile_Engine = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Projectile_Engine, 0.022 )
    call TriggerAddAction( gg_trg_Projectile_Engine, function Projectile_Engine_Actions )
endfunction
 
Level 11
Joined
Apr 6, 2008
Messages
760
Those 2 triggers could use alot of clearning up and improving.

First of use structs easier to read the code and easier too work with. (if you have JNGP will say)

Second, TriggerRegisterTimerEventPeriodic( gg_trg_Projectile_Engine, 0.022 ) Use a timer instead.

GetTerrainVarianceBJ(l2) this is not the same as GetLocationZ and its also a bj which is bad mkay.

JASS:
function Projectile_Set_Conditions takes nothing returns boolean
    if ( GetUnitTypeId(GetAttacker()) == 'H00D' ) then
        return true
    endif
    return false
endfunction

Do Condition functions like this (if they dont need to be more advanced).

JASS:
function Projectile_Set_Conditions takes nothing returns boolean
    return ( GetUnitTypeId(GetAttacker()) == 'H00D' )
endfunction

My idea too you is to watch some spells by other people, see how they made their spells work, this kinda look abit like converted GUI too me.
 
Level 5
Joined
Feb 6, 2008
Messages
134
Can you create sample map with Z linear moving in JASS? i tried a lot of variations but the missle moving isn't linear. thx
 
Status
Not open for further replies.
Top