Snippet Advanced Projectile Motion Experiment

13lade619

is now a game developer :)
Reaction score
398
MAJOR UPDATE!! SYSTEMIZED!!

The purpose of this Snippet/Tutorial is to show you the results of the experiments I made
about advanced projectile motion,
more precisely creating an XY arc with a Z arc simultaneously.


90811Projectile.gif

System In action, but just movement.. no effects.
I used an arrow to show that the facing is constantly modified for aesthetic purposes.

Before we start, there are two people i want to thank because I based my codes from their calculations.
Vexorian > for his Caster System i used for the vertical arc
emjlr > for his Wild Axes spell i used for sideways arc

as you can see it currently only targets points for now... sorry?

Ok, here’s the new code.
Complete with config header

You can now use
“function ProjectileLaunch takes unit caster, location loc1, location loc2 returns nothing” to launch a projectile from another trigger to make things easier.

You can edit the main parameters on the “TheProjectile” trigger.
Check the “Sample” Trigger for an example.

* you can edit the function to add more parameters and make it a system though..

First piece... is the Projectile function which you can modify.
JASS:
library TheProjectile requires KLHV
//REQUIREMENTS : Kattana's Local Handle Vars, yes.. so old school.
//             :::::: the system must be in a trigger, not map header.
//             :::::::::::: name a library "KLHV" and it willl be ok.
//             : Dummy unit in the OE
//             : dummy.mdl in the imported models << very important, don't forget it.
//             : a triggering ability, change the condition below.

// use the function ProjectileLaunch takes unit caster, location loc1, location loc2 returns nothing
// configure other parameters below.
// you can edit the function to add more parameters and make it a system though..

//Configurables
globals
    private constant real Z1 = 100          // start loc z
    private constant real Z2 = 100          // end loc z
    private constant real ARC = 0.35        // same as OE, 0 to 1. affected by arcspeed.
    private constant real ARCSPEED = 1000   // rate at which the arc changes, low speed makes larger arc.
    private constant real ARCW = 300        // width of horizontal arc. increase or decrease.
    private constant real LA = 45           // launch angle. you can switch to -45 to launch in other direction.
    private constant real RSPEED = 0.05    // affects REAL speed of the projectile, no direct conversion to wc3 speed rate.
    private constant string MISSILE = "Abilities\\Weapons\\Arrow\\ArrowMissile.mdl"
endglobals

//=======================================================================================
//          NO TOUCHING???
//=======================================================================================

//The Struct.
struct projectile
    unit proj     
    real x1        
    real y1        
    real x2        
    real y2        
    real z1        
    real z2        
    real arcspeed   
    real arc       
    real face  
    boolean done    
    effect fx     
    
    real A         // from emjlr's Wild Axes spell
    real outx      
    real outy
    real s2        
endstruct

//=======================================================================================

//Movement Trigger, READ, but DONT edit.
function PMove takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local projectile p = GetHandleInt(t,"pstruct")

    //Calculations from Vexorian's Projectile System.
    //     calculates the vertical arc.
    local real d = p.arcspeed*0.035
    local real od = SquareRoot(Pow(GetUnitX(p.proj)-p.x2,2) +  Pow(GetUnitY(p.proj)-p.y2,2))
    local real time = od / p.arcspeed
    local real zspeed = (p.z2-GetUnitFlyHeight(p.proj)+0.5*p.arc*time*time)/time

    //Calculataions from emjlr's Wild Axes spell.
    //     calculates the horizontal arc.
    local real b = 1.-p.A
    local location l

    // when the missile reaches endpoint.
    if( p.A < 0)then
        call ExplodeUnitBJ(p.proj)
        call DestroyEffect(p.fx)
        call SetUnitAnimationByIndex(p.proj,91)
        set p.done=true
    else    
        //VERTICAL ARC, from Vexorian 
        call SetUnitFlyHeight(p.proj,GetUnitFlyHeight(p.proj)+zspeed*.035,0)
        //Correcting animation, by Vexorian
        call SetUnitAnimationByIndex(p.proj,R2I(Atan2(zspeed,p.arcspeed)* bj_RADTODEG)+90) //Thanks infrane!

        //Corrective Facing >by me, 13lade619<
            set l = Location(p.x1*p.A*p.A+p.outx*2*p.A*b+p.x2*b*b, p.y1*p.A*p.A+p.outy*2*p.A*b+p.y2*b*b)
            call SetUnitFacingToFaceLocTimed(p.proj,l, 0)

        //HORIZONTAL ARC, from emjlr.
        call SetUnitX(p.proj,p.x1*p.A*p.A+p.outx*2*p.A*b+p.x2*b*b)
        call SetUnitY(p.proj,p.y1*p.A*p.A+p.outy*2*p.A*b+p.y2*b*b)
        set p.A = p.A-p.s2

    endif
        
    //Anti-Leaks..
    set t = null
    call RemoveLocation(l)
endfunction

//=======================================================================================
function AdProjectileLaunch takes unit caster, location loc1, location loc2 returns nothing
    // set necessary variables.
    local projectile p = projectile.create()
    local timer t = CreateTimer()

    set p.x1 = GetLocationX(loc1) 
    set p.y1 = GetLocationY(loc1) 
    set p.x2 = GetLocationX(loc2) 
    set p.y2 = GetLocationY(loc2)
     
    // NEEDED : starting and ending Z's.
    set p.z1 = Z1
    set p.z2 = Z2
    
    // facing angle and booelan, dont change.
    set p.face = Atan2BJ(p.y2-p.y1,p.x2-p.x1)
    set p.done = false
    
    // NEEDED
    set p.arcspeed = ARCSPEED    // affects the rate where the arc changes, lower generates bigger arc. calc by Vexorian.
    set p.arc = (ARC) * 8000 // vertical arc. change only within the (). calculation by Vexorian.
    
    set p.A = 1 // variable from emjlr.. dont change.
    
    //NEEDED 
    // you can change 555. higher is larger horizontal arc.
    // and change -45 to +45 to launch from the other side.
    set p.outx = p.x1+ ARCW *Cos(Atan2(p.y2-p.y1,p.x2-p.x1)+(LA))
    set p.outy = p.y1+ ARCW *Sin(Atan2(p.y2-p.y1,p.x2-p.x1)+(LA))
    // Affects the REAL SPEED of the projectile, lower is slower.
    set p.s2 = RSPEED
        
    //Starting movement, move to the PMove Function.
    set p.proj = CreateUnitAtLoc(GetOwningPlayer(caster),'e001',loc1,p.face)
    set p.fx = AddSpecialEffectTarget(MISSILE,p.proj,"origin")
    call SetUnitFlyHeight(p.proj,p.z1,0)
    call SetHandleInt(t,"pstruct",p)
    call TimerStart(t,.035,true, function PMove)

    // wait until the projectile hits.
    // by Vexorian. 
    loop
        exitwhen p.done
        call TriggerSleepAction(0)
    endloop

    // take care of everything...
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set p.proj = null
    call p.destroy()
endfunction
endlibrary

Second is the sample trigger for using it.
JASS:
function Trig_Sample_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Trig_Sample_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local location loc1 = GetUnitLoc(caster)
    local location loc2 = GetSpellTargetLoc()

    call AdProjectileLaunch(caster, loc1, loc2) //just the minor details though..
    
    call BJDebugMsg("POINT REACHED. Add Effects!")
    
    call RemoveLocation(loc1)
    call RemoveLocation(loc2)
    set caster = null
endfunction

//===========================================================================
function InitTrig_Sample takes nothing returns nothing
    set gg_trg_Sample = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Sample, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Sample, Condition( function Trig_Sample_Conditions ) )
    call TriggerAddAction( gg_trg_Sample, function Trig_Sample_Actions )
endfunction

as you can see, i split the snippet into two because the place where you can add effects is pretty deep down in the first trigger. so i decided to turn the first part into a function.
 

Attachments

  • projectile.w3x
    36.8 KB · Views: 243

Romek

Super Moderator
Reaction score
964
I tested the map, without even glancing at the code.

- Uninitialized variable "l" used in PMove() (3-5 times)
- Uninitialized variable "l" used in Trig_projectile_Actions()
 

Romek

Super Moderator
Reaction score
964
Oh, they aren't save errors. I'm using Grimoire, and it reports errors like that in-game.
It saved without problems, and I haven't looked at the code.

From a quick glance, I can't see where you're using an uninitialized variable. It seems like a problem with grimoire... o_O

Also, you may want to null those locations. :)
 
Reaction score
456
> It seems like a problem with grimoire... o_O
No. He's removing uninitialized location "l" in the Trig_projectile_Actions() function. Same for the second one - location "l" isn't initialized in PMove() if p.A < 0.

And the random amount of times it shows the PMove() warning is caused by inaccurate TriggerSleepAction in the loop :p.
 

Viikuna

No Marlo no game.
Reaction score
265
What if I want to use vector components, like velocityX, velocityY and velocityZ ?

How can I calculate the correct animation index, by using them?
 

13lade619

is now a game developer :)
Reaction score
398
What if I want to use vector components, like velocityX, velocityY and velocityZ ?

How can I calculate the correct animation index, by using them?

hehe... funny thing is..
i dont exactly know how the values work...

i just merged two different systems from two people in a chance to produce my desired effects...

i only know that this increases that or that.. lolz..
 

13lade619

is now a game developer :)
Reaction score
398
NIce system but a bit specific and not easy to use.

yes.. frankly, it's not a system yet 'cause there arent any custom functions and its non configurable..
and the values are a bit guesswork for now..

maybe i'll be making it into a system when i learn more vJASS.
 

13lade619

is now a game developer :)
Reaction score
398
BUMPING.

new code up, systematized, config header, and can now be used in spells.
it's now consisted of 2 triggers.

and please let me know if there are errors with my library/globals.... maybe i missed something.
it's my first library type code.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Effects should be independent on function calls? (Maybe?)

function ProjectileLaunch takes unit caster, location loc1, location loc2, string eff returns nothing
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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