- Joined
- Sep 21, 2007
- Messages
- 517
alright, im not a really good mathematician, so im guesing i messed up in the math in the drag, anyways, let me tell you the story first: i started creating a movement acceleration system that deaccelerates units when they go over higher terrains, and accelerates them when going down, the only problem i got was that the player can turn down, gain acceleration and go over a higher terrain that he isnt supposed to be able to pass due to his deacceleration.
so i decided to create a movement drag, triggering isnt that efficient yet tho, but il improve it later on:
btw it may be because im using GetHandleId(), but thats a native and should work accordingly :/
ty for your time
PROBLEM FIXED: IT WAS WITH HANDLES
so i decided to create a movement drag, triggering isnt that efficient yet tho, but il improve it later on:
JASS:
library Acceleration
globals
private timer t = CreateTimer()
private group accelUnits = CreateGroup()
private location Zloc = Location(0.,0.)
private integer maxAccel = 0
private real tIteration = 0.15 // timer periodic iteration
private real checkDist = 10.
private constant real gravity = -9.81 // gravity's real value, make it lower to lower the acceleration/deacceleration change
// drag globals
private timer d = CreateTimer()
private real dragIteration = 0.06 // drag timer periodic iteration
private group dragGroup = CreateGroup()
private integer maxDrag = 0
private real array drag
private real array angle
private constant real dragGravity = gravity*dragIteration*-1
private boolean array isDrag
private real NoDrag = 15. //maximum difference in Z that cannot cause any drag
endglobals
private function GetLocZ takes real x, real y returns real
call MoveLocation(Zloc, x, y)
return GetLocationZ(Zloc)
endfunction
private function coreDrag takes nothing returns nothing
local unit e = GetEnumUnit()
local integer i = GetHandleId(e)
local real a = angle[i]
local real x = GetUnitX(e)
local real y = GetUnitY(e)
local real x2 = x+checkDist*Cos(a)
local real y2 = y+checkDist*Sin(a)
local real diffZ = GetLocZ(x2,y2)-GetLocZ(x,y)
if diffZ < -NoDrag or diffZ > NoDrag then
set drag[i] = drag[i] + dragGravity
call SetUnitPosition(e, x+drag[i]*Cos(a), y+drag[i]*Sin(a))
else
call GroupRemoveUnit(dragGroup, e)
set isDrag[i] = false
set maxDrag = maxDrag - 1
if maxDrag == 0 then
call PauseTimer(d)
endif
endif
set e = null
endfunction
private function DragUnits takes nothing returns nothing
call ForGroup(dragGroup, function coreDrag)
endfunction
private function coreAccel takes nothing returns nothing
local unit e = GetEnumUnit()
local real f = GetUnitFacing(e)*bj_DEGTORAD
local real x = GetUnitX(e)
local real y = GetUnitY(e)
local real x2 = x+checkDist*Cos(f)
local real y2 = y+checkDist*Sin(f)
local real defaultSpeed = GetUnitDefaultMoveSpeed(e)
local real newSpeed = defaultSpeed+(gravity*(GetLocZ(x2,y2)-GetLocZ(x,y)))
if newSpeed > defaultSpeed then
if isDrag[GetHandleId(e)] == false then
set isDrag[GetHandleId(e)] = true
set drag[GetHandleId(e)] = defaultSpeed*dragIteration
set angle[GetHandleId(e)] = f
set maxDrag = maxDrag + 1
call GroupAddUnit(dragGroup, e)
call TimerStart(d, dragIteration, true, function DragUnits)
endif
else
call SetUnitMoveSpeed(e, newSpeed)
endif
set e = null
endfunction
private function AccelerateUnits takes nothing returns nothing
call ForGroup(accelUnits, function coreAccel)
endfunction
function AddUnitAcceleration takes unit u returns nothing
if u == null then
return
endif
call GroupAddUnit(accelUnits, u)
set maxAccel = maxAccel + 1
call TimerStart(t, tIteration, true, function AccelerateUnits)
endfunction
function RemoveUnitAcceleration takes unit u returns nothing
if u == null then
return
endif
call GroupRemoveUnit(accelUnits, u)
call SetUnitMoveSpeed( u, GetUnitDefaultMoveSpeed(u) )
set maxAccel = maxAccel - 1
if maxAccel == 0 then
call PauseTimer(t)
endif
endfunction
endlibrary
btw it may be because im using GetHandleId(), but thats a native and should work accordingly :/
ty for your time
PROBLEM FIXED: IT WAS WITH HANDLES
Last edited: