darkbeer
Beer is Good!
- Reaction score
- 84
Hey,
I just wanted to make my own jump system, so i tried to code it, but unfortunately i don't get how to calculate the height of a unit while its jumping.
Heres the code I use:
Hope someone got any ideas about it, ill also try to make it dynamic so it the height will adept to the ground level when jumping over a canyon or sth. like that.
thankfull for any suggestions
I just wanted to make my own jump system, so i tried to code it, but unfortunately i don't get how to calculate the height of a unit while its jumping.
Heres the code I use:
JASS:
library JumpSystem
globals
integer JumpTotal = 0
timer JumpTimer = CreateTimer()
JumpStruct array JumpAr
endglobals
struct JumpStruct
unit u
real dist
real x
real speed
real height
real angle
location target
boolean destroypls
endstruct
constant function GetJumpPeriode takes nothing returns real
return 0.03
endfunction
function EndJump takes unit u returns nothing
call SetUnitPathing(u, true)
call UnitRemoveAbility(u, 039;Amrf039;)
endfunction
function JumpLoop takes nothing returns nothing
local JumpStruct dat = JumpStruct.create()
local integer i = 0
local location loc
local location Offset
local real height
local real PosZ
call DisplayTextToForce(GetPlayersAll(), "aa")
loop
exitwhen i == JumpTotal
set dat = JumpAr<i>
if dat.destroypls == true then
call dat.destroy()
set JumpAr<i> = JumpAr[JumpTotal - 1]
set JumpTotal = JumpTotal - 1
set i = i - 1
else
set loc = GetUnitLoc(dat.u)
set Offset = PolarProjectionBJ(loc, dat.speed, dat.angle)
call SetUnitPositionLoc(dat.u, Offset)
set PosZ = GetLocationZ(Offset)
if dat.x <= dat.dist/2 then
set height =( SquareRoot( dat.height * dat.height - (dat.dist/2 - dat.x) * (dat.dist/2 - dat.x))) //these are the things that give me problems^^
else
set height = ( SquareRoot( dat.height * dat.height - (dat.x - dat.dist/2) * (dat.x - dat.dist/2))) //these are the things that give me problems^^
endif
call SetUnitFlyHeight(dat.u, height, 0 )
set dat.x = dat.x + dat.speed
if dat.x >= dat.dist then
set dat.destroypls = true
call EndJump(dat.u)
endif
call RemoveLocation(Offset)
set Offset = null
endif
set i = i + 1
endloop
if JumpTotal == 0 then
call PauseTimer(JumpTimer)
endif
endfunction
function StartJump takes unit u, real height, real time, location target returns nothing
local location loc = GetUnitLoc(u)
local real dist = DistanceBetweenPoints(loc, target)
local JumpStruct dat = JumpStruct.create()
set dat.target = target
set dat.u = u
set dat.dist = dist
set dat.x = 0
set dat.speed = dist / time * GetJumpPeriode()
set dat.height = height
set dat.destroypls = false
set dat.angle = AngleBetweenPoints(loc, target)
set JumpAr[JumpTotal] = dat
call SetUnitPathing(u, false)
call UnitAddAbility(u, 039;Amrf039;)
if JumpTotal == 0 then
call TimerStart(JumpTimer, GetJumpPeriode(), true, function JumpLoop)
endif
set JumpTotal = JumpTotal + 1
call RemoveLocation(loc)
set loc = null
endfunction
endlibrary
function Trig_Jump_System_Actions takes nothing returns nothing
endfunction
//===========================================================================
function InitTrig_Jump_System takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerAddAction( gg_trg_Jump_System, function Trig_Jump_System_Actions )
set t = null
endfunction
</i></i>
Hope someone got any ideas about it, ill also try to make it dynamic so it the height will adept to the ground level when jumping over a canyon or sth. like that.
thankfull for any suggestions