- Joined
- Jun 26, 2020
- Messages
- 1,928
Hello, I'm have another system, that is a Jump System based on the Paladon's Jump System, but this includes horizontal curvature, I know that there can be better systems, but I still wanna share this I hear what things I can improve.
PD: The used global variables are created in GUI, but for you have them:
PD2: Edited
JASS:
//Jump System based on the Paladon's Jump System
//If you use GUI do:
//
// Set JS_Unit = "The jumper" (Necessary)
// Set JS_TargetPoint = "The point of landing" (Necessary)
// Set JS_Speed = "The distance per second" (Necessary)
// Set JS_Height = "The ratio between the max. height and the max distance" (Optional, if you add nothing the unit will move in a line)
// Set JS_Curve = "The horizontal curvature, works like height, if the value is positive, the curve wilt be to the left, if is negative, to the right" (Optional)
// Set JS_Effect = "The effect you wanna see during the jump attached to the jumper" (Optional)
// Set JS_Animation = "The animation of the jumper during the jump" (Optional)
// Set JS_AnimationSpeed = "The speed of the animation of the jumper" (Optional / Default value 1.00)
// Trigger - Run Jump_System_Data (ignoring conditions)
//
// If you don't wanna set the optional values don't use them, the values always will be cleaned after use them.
//
//If you use Jass do:
//
// call JumpSystemData(<Unit>,<Target>,<Speed>,<Height>,<Curve>,<Effect>,<Animation>,<AnimationSpeed>)
//
// Refering to the same values previously seen
//
//To know if the unit is jumping use "<Unit> is in JS_group Equal to True"
//
//To refer when the unit is landing use the event "Nojump_event becomes Equal to 1.00" and to refer the jumper use the variable "Nojump_Unit"
library JumpSystem initializer Init uses TimerUtils, start //This start is something of my map, erase it
struct JumpSystem
static constant real INTERVAL=0.01
unit jumper
real speed
real height
real line_x
real line_y
real var_line_x
real var_line_y
real var_curve_x
real var_curve_y
real var_realtimer
string myeffect
string animationtag
real distance
real reacheddistantance
real angle
real realtimer
real addrt
timer t
static method create takes unit jumper, location target, real speed, real height_ratio, real curve, string myeffect, string animationtag, real animationspeed returns thistype
local thistype this=thistype.allocate()
local real dx=GetLocationX(target)-GetUnitX(jumper)
local real dy=GetLocationY(target)-GetUnitY(jumper)
//Data
set this.jumper=jumper
set this.speed=speed*thistype.INTERVAL
set this.myeffect=myeffect
set this.animationtag=animationtag
//The values of the movement
set this.distance=SquareRoot(dx*dx+dy*dy)
set this.height=height_ratio*this.distance
set this.line_x=GetUnitX(jumper)
set this.line_y=GetUnitY(jumper)
set this.angle=Atan2(dy,dx)
set this.var_line_x=this.speed*Cos(this.angle)
set this.var_line_y=this.speed*Sin(this.angle)
set this.reacheddistantance=0.00
set this.var_curve_x=-curve*this.distance*Sin(this.angle)
set this.var_curve_y=curve*this.distance*Cos(this.angle)
set this.realtimer=0.00
set this.var_realtimer=0.00
call SetUnitPathing(jumper,false)
call SetUnitTimeScale(jumper,animationspeed)
call SetUnitAnimation(jumper,animationtag)
call UnitAddAbility(jumper,'Arav')
call UnitRemoveAbility(jumper,'Arav')
set this.addrt=bj_PI*this.speed/this.distance
set this.t=NewTimerEx(this)
call TimerStart(this.t,thistype.INTERVAL,true,function thistype.callPeriodic)
return this
endmethod
method periodic takes nothing returns nothing
set this.line_x=GetUnitX(this.jumper)-this.var_realtimer*this.var_curve_x+this.var_line_x
set this.line_y=GetUnitY(this.jumper)-this.var_realtimer*this.var_curve_y+this.var_line_y
call QueueUnitAnimation(this.jumper,this.animationtag)
set this.realtimer=this.realtimer+this.addrt
set this.var_realtimer=Sin(this.realtimer)
call SetUnitFlyHeight(this.jumper,this.var_realtimer*this.height,1000000000.00)
call SetUnitPosition(this.jumper,this.line_x+this.var_realtimer*this.var_curve_x,this.line_y+this.var_realtimer*this.var_curve_y)
set this.reacheddistantance=this.reacheddistantance+this.speed
if GetRandomInt(1,5)==1 then
call DestroyEffect(AddSpecialEffectTarget(this.myeffect,this.jumper,"chest"))
endif
endmethod
static method callPeriodic takes nothing returns nothing
local JumpSystem this=GetTimerData(GetExpiredTimer())
if this.reacheddistantance<this.distance then
call this.periodic()
else
call this.destroy()
endif
endmethod
method destroy takes nothing returns nothing
set udg_Nojump_Unit=this.jumper
set udg_Nojump_event=0.00
set udg_Nojump_event=1.00
set udg_Nojump_event=0.00
call ReleaseTimer(this.t)
call GroupRemoveUnit(udg_JS_group,this.jumper)
//I create this function for my map to enable the colision of the unit under
//specific conditions, change this to "SetUnitPathing(this.caster,true)" or your own "OnColision"
call OnColision(this.jumper)
set this.t=null
set this.jumper=null
call this.deallocate()
endmethod
endstruct
//For Jass
function JumpSystemData takes unit jumper, location target, real speed, real height_ratio, real curve, string myeffect, string animationtag, real animationspeed returns nothing
call GroupAddUnit(udg_JS_group,jumper)
call JumpSystem.create(jumper,target,speed,height_ratio,curve,myeffect,animationtag,animationspeed)
endfunction
//For GUI
private function actions takes nothing returns nothing
call GroupAddUnit(udg_JS_group,udg_JS_Unit)
call JumpSystem.create(udg_JS_Unit,udg_JS_TargetPoint,udg_JS_Speed,udg_JS_Height,udg_JS_Curve,udg_JS_Effect,udg_JS_Animation,udg_JS_AnimationSpeed)
set udg_JS_Unit=null
set udg_JS_TargetPoint=null
set udg_JS_Speed=0.00
set udg_JS_Height=0.00
set udg_JS_Curve=0.00
set udg_JS_Effect=""
set udg_JS_Animation=""
set udg_JS_AnimationSpeed=1.00
endfunction
private function Init takes nothing returns nothing
set udg_Jump_System_Data=CreateTrigger()
set udg_JS_AnimationSpeed=1.00
call TriggerAddAction(udg_Jump_System_Data,function actions)
endfunction
endlibrary
JASS:
globals
unit udg_JS_Unit=null
location udg_JS_TargetPoint=null
real udg_JS_Speed=0.00
real udg_JS_Height=0.00
real udg_JS_Curve=0.00
string udg_JS_Effect=""
string udg_JS_Animation=""
real udg_JS_AnimationSpeed=1.00
group udg_JS_group=CreateGroup()
real udg_Nojump_event
unit udg_Nojump_Unit
trigger udg_Jump_System_Data
endglobals
Last edited: