- Joined
- Sep 12, 2008
- Messages
- 657
Okay.. i've made a code that makes a unit jump, and loose height every 0.01 seconds. its pulled by "gravity", which is a real variable in my game, effecting all units.
My system is VJASS,
i've took the idea of the "Mountain check" from diehard@azeroth,
but i didnt take his system, i made my own.
Tho, diehard@azeroth did teach me how to use it, so credits to him =].
Heres the code:
Again, i remind, this is Vjass, not jass ;p.
Thanks in advance =]
My system is VJASS,
i've took the idea of the "Mountain check" from diehard@azeroth,
but i didnt take his system, i made my own.
Tho, diehard@azeroth did teach me how to use it, so credits to him =].
Heres the code:
JASS:
scope RS initializer INIT
globals
private real Gravity = 0.75 // this will be the gravity for all units in game.
// Gravity info: @@ Must Read! @@
// The gravity will be used on all units,
// 0.75 is quite alot, i'd recommand 0.50 or else it wont be able to count all units.
// The only problem is that if its not 1, or 0.01, or 0.1, it wont be able to loop thru all numbers.
// If its 0.75 the starting height(variable X in Test trigger), must be a multiple of 0.75.
// If you'r good in math, look at how to use other numbers.
// If the number is higher then 0, the loop will decrease height each 0.01 seconds,
// The math will do this: CURRENT flying height of unit - gravity = new height.
// If the number is LOWER then 10, the system will remove the unit from the loop,
// stop changing his height.
// Tho will remove his height and restart it to 0.
// this will be how the system math works:
// Starting heiht * 0.75 = amount of loops.
// 150 starting height with 0.75 gravity will be:
// 150 * 0.75 = 112.5
// 112.5 loops in total. that means 112.5 / 150 = 0.75
// 0.75 * 100 (miliseconds in a second), is 75.
// 75 height loose in a second.
// hope you understend how to use this,
// good luck on you'r map =]
private real x
private real y
private location l
private group Group = CreateGroup()
private integer c
private real x2
private real y2
public real z1
public real z2
private location l2
//privates decleration
public boolean UIGU // Unit Is Moving Up-Wards, wont recommand touching.
public boolean UIGD // Unit Is Moving Down-Wards, wont recommand touching.
public boolean UISS // Unit Is Staying At Same Terrain, wont recommand touching.
public real DiffrenceInZ // dont touch, this defines the diffrence in height of terrain. used to jump.
endglobals
private function Actions takes nothing returns nothing
local unit u
local real f
set u = GetEnumUnit()
set f = GetUnitFlyHeight(u)
if f > 0 then
call SetUnitFlyHeight( u, f - Gravity, 0 )
endif
if f <= 10 then
call GroupRemoveUnit(Group, u)
endif
endfunction
private function GActions takes nothing returns nothing
call ForGroup(Group, function Actions)
endfunction
public function Actions2 takes unit u returns nothing
set x2 = GetUnitX(u)
set y2 = GetUnitY(u)
set l2 = Location (x2, y2)
set z1 = GetLocationZ(l2)
//----------------------------------------------------------------
set x = GetLocationX(l2) + 50 * Cos(GetUnitFacing(u) * bj_DEGTORAD)
set y = GetLocationY(l2) + 50 * Sin(GetUnitFacing(u) * bj_DEGTORAD)
set l2 = Location(x2, y2)
set z2 = GetLocationZ(l2)
if z1 > z2 then
set DiffrenceInZ = z1 - z2
set UIGU = true
set UIGD = false
set UISS = false
elseif z1 < z2 then
set DiffrenceInZ = z2 - z1
set UIGD = true
set UISS = false
set UIGU = false
elseif z1 == z2 then
set DiffrenceInZ = 0
set UISS = true
set UIGD = false
set UIGU = false
endif
call RemoveLocation(l)
set l = null
endfunction
public function Add takes unit u, real x returns nothing
if not IsUnitInGroup(u, Group) then
call GroupAddUnit(Group, u)
else
return
endif
call UnitAddAbility(u, 'Amrf')
call UnitRemoveAbility(u, 'Amrf')
call Actions2(u)
if UIGD == true then
call SetUnitFlyHeight(u, x2 + 50, 0)
set UIGD = false
elseif UIGU == true then
call SetUnitFlyHeight(u, x2 - 50, 0)
set UIGU = false
elseif UISS == true then
call SetUnitFlyHeight(u, x2, 0)
set UISS = false
endif
endfunction
private function INIT takes nothing returns nothing
local trigger JS = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic(JS, 0.003 )
call TriggerAddAction(JS, function GActions )
endfunction
endscope
Again, i remind, this is Vjass, not jass ;p.
Thanks in advance =]
Last edited: