Jonnycakes
New Member
- Reaction score
- 6
Hi, I started messing around with a flight system today that utilizes the arrow keys. The system works by creating one flying unit for each player (more specifically a ground unit that has had crow form added/removed from it) that is then controlled with the arrow keys (the unit moves forward at a fixed rate. Left/Right turn the unit and Up/Down change its height). The camera locks behind that unit for the player. The problem is this:
When I added some noise to the terrain to test the system's height adjustment, the flying unit started going batsh**. When a unit flies over varied terrain, the camera level stays normal, but the unit's fly height starts changing inversely with the height of the terrain (i.e. if the terrain lowers, the unit starts flying higher. If the terrain raises, the unit starts flying lower). I have no idea why this is-the "base height" (height of the unit disregarding terrain height) stays the same, and if the unit flies back to a level surface, all is well. It is quite strange...
Anyway, here is my trigger. Each unit's data is stored as an instance of a struct in an array. This function loops through said struct array and does periodic actions for each unit.
When I added some noise to the terrain to test the system's height adjustment, the flying unit started going batsh**. When a unit flies over varied terrain, the camera level stays normal, but the unit's fly height starts changing inversely with the height of the terrain (i.e. if the terrain lowers, the unit starts flying higher. If the terrain raises, the unit starts flying lower). I have no idea why this is-the "base height" (height of the unit disregarding terrain height) stays the same, and if the unit flies back to a level surface, all is well. It is quite strange...
Anyway, here is my trigger. Each unit's data is stored as an instance of a struct in an array. This function loops through said struct array and does periodic actions for each unit.
JASS:
scope moveloop initializer init
private function actions takes nothing returns nothing
local integer i=0
local unitdata temp
local location loc
local real z
loop
exitwhen i==playerstotal
set temp=ud<i>
set temp.velocity=temp.velocity+temp.accelleration
if temp.velocity<0 then
set temp.velocity=0
set temp.accelleration=0
endif
if temp.left and not temp.right then
set temp.facing=temp.facing+.1
elseif temp.right and not temp.left then
set temp.facing=temp.facing-.1
endif
call SetUnitFacing(temp.u, Rad2Deg(temp.facing))
set temp.x=GetUnitX(temp.u)
set temp.y=GetUnitY(temp.u)
if temp.up and not temp.down then
set temp.height=temp.height+10
elseif temp.down and not temp.up then
set temp.height=temp.height-10
endif
set temp.x=temp.x+temp.velocity*Cos(temp.facing)
set temp.y=temp.y+temp.velocity*Sin(temp.facing)
call SetUnitPosition(temp.u, temp.x, temp.y)
set loc=Location(temp.x, temp.y)
set z=GetLocationZ(loc)
if temp.height-z<HEIGHTMIN then
set temp.height=z+HEIGHTMIN
endif
if temp.height>HEIGHTMAX then
set temp.height=HEIGHTMAX
endif
call SetUnitFlyHeight(temp.u, temp.height-z, 0)
if GetLocalPlayer()==temp.p then
call PanCameraToTimed(temp.x-10*Cos(temp.facing), temp.y-10*Sin(temp.facing), 0)
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 330, 0)
call SetCameraField(CAMERA_FIELD_ROTATION, Rad2Deg(temp.facing), 0)
call SetCameraField(CAMERA_FIELD_ZOFFSET, temp.height, 0)
endif
//call BJDebugMsg(R2S(GetUnitFlyHeight(temp.u)))
//call BJDebugMsg(R2S(z))
call RemoveLocation(loc)
set i=i+1
endloop
set loc=null
endfunction
//===========================================================================
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerAddAction(t, function actions)
call TriggerRegisterTimerEvent(t, .04, true)
endfunction
endscope</i>