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.
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.
Second is the sample trigger for using it.
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.
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.
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),039;e001039;,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() == 039;A000039;
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.