| 08-20-2009, 05:13 PM | #1 |
okay, hmm... I've been trying to do something like the image (yes I'm really good at drawing in paint) but the missile doesn't go exactly like the trajectory, it follows the path height, instead of continuing straight forward, and also when it hits the ground it should stop, but no, it just continues. ![]() So I ask if there is a formula to continuously calculate the new missile height correctly to avoid this annoying issues. There is a Jump system on hive which does something like this, but when I tried to use the formula to calculate the height, it remained screwed. |
| 08-20-2009, 05:22 PM | #2 |
Are you already using the LocationZ+FlyHeight method? Maybe you could post the code your using. |
| 08-20-2009, 05:39 PM | #3 |
yap I tried. here it is: JASS:call MoveLocation( d.loc, d.cx, d.cy ) set d.cz = ParabolicMovement( d.mh, d.md, d.cd ) - GetLocationZ( d.loc ) + d.sz call SetUnitFlyHeight( d.m, d.cz, 0.00 ) |
| 08-20-2009, 06:01 PM | #4 |
Did you add and remove the crow form ability? |
| 08-20-2009, 07:09 PM | #5 |
yap I did. It flys but still follows the terrain height like a normal flying unit |
| 08-20-2009, 07:48 PM | #6 |
There must be a field regarding height sampling range... |
| 08-20-2009, 08:49 PM | #7 |
a better explanation, could actually help please :) |
| 08-20-2009, 09:12 PM | #8 |
The unit can't have flying-type movement in the OE; it must be added through the Crow Form trick. |
| 08-20-2009, 09:52 PM | #9 |
but I already do that, I told that before |
| 08-20-2009, 09:57 PM | #10 |
Eh, I was just saying to make sure it has 'ground' movement type in the OE. |
| 08-20-2009, 10:09 PM | #11 |
Actually, "hover" movement type is the best, since ground gets screwy under water because the "ground" unit's flying height is measured from the ground while GetLocationZ measures from the water surface. |
| 08-22-2009, 10:53 PM | #12 |
nope, that doesn't solve the problem either. I remade the system, it's incomplete but should work okay, but now the missile doesn't even move, it creates and stops, right after. It stops because supposedly the x and y aren't walkable. Anyway here is the system: Jump System:library DEJump initializer Init private keyword Data globals private timer tim = CreateTimer( ) private constant real DELAY = 0.03 private integer total = 0 private Data array dat private location loc = Location( 0., 0. ) endglobals // ================================================================ // ================================================================ globals //private constant real MAX_RANGE = 10.0 public real X = 0.0 public real Y = 0.0 private rect r private item check private item array hidden private integer hiddenMax = 0 endglobals private function Init takes nothing returns nothing set check = CreateItem('ciri',0,0) call SetItemVisible(check,false) set r = Rect(0.0,0.0,128.0,128.0) endfunction private function HideBothersomeItem takes nothing returns nothing if IsItemVisible(GetEnumItem()) then set hidden[hiddenMax]=GetEnumItem() call SetItemVisible(hidden[hiddenMax],false) set hiddenMax=hiddenMax+1 endif endfunction private function IsTerrainWalkable takes real x, real y, real maxrange returns boolean call MoveRectTo(r, x,y) call EnumItemsInRect(r,null,function HideBothersomeItem) call SetItemPosition(check,x,y) set X = GetItemX(check) set Y = GetItemY(check) call SetItemVisible(check,false) loop exitwhen hiddenMax<=0 set hiddenMax=hiddenMax-1 call SetItemVisible(hidden[hiddenMax],true) set hidden[hiddenMax]=null endloop return (x-X)*(x-X)+(y-Y)*(y-Y) < maxrange*maxrange endfunction // ================================================================ // ================================================================ private function Loop takes nothing returns nothing local Data d local integer i = 0 loop exitwhen i >= total set d = dat[i] set d.cd = d.cd + d.s //set Data.nH = dat.X*(dat.MaxDist - dat.Dist)*(dat.Dist / dat.MaxDist) - GetLocationZ(Data.Loc) + dat.Z set d.z = d.mh * ( d.md - d.cd ) * ( d.cd / d.md ) - GetLocationZ( loc ) + d.uz call SetUnitFlyHeight( d.c, d.z, 0. ) set d.x = d.x + d.s * d.cos set d.y = d.y + d.s * d.sin if IsTerrainWalkable( d.x, d.y, d.ITWrd ) then call DestroyEffect( AddSpecialEffectTarget( d.fx, d.c, "chest" ) ) call SetUnitX( d.c, d.x ) call SetUnitX( d.c, d.y ) else call d.destroy( ) endif if d.cd >= d.md then call d.destroy( ) endif set i = i + 1 endloop if total == 0 then call PauseTimer( tim ) endif endfunction private struct Data unit c real mh //max height real md //max distance real cd = 0. //current distance real s //speed real rd = 0. real x real y real z = 0. real uz //unit z real cos real sin real ITWrd = 10. //Is Terrain Walkable radius string fx effect ef integer id private method Start takes nothing returns nothing if total == 0 then call TimerStart( tim, DELAY, true, function Loop ) endif set dat[total] = this set .id = total set total = total + 1 endmethod static method coreCreate takes unit c, string afx returns Data local Data d = Data.allocate( ) set d.c = c set d.x = GetUnitX( d.c ) set d.y = GetUnitY( d.c ) call MoveLocation( loc, d.x, d.y ) set d.uz = GetLocationZ( loc ) + GetUnitDefaultFlyHeight( d.c ) set d.ef = AddSpecialEffectTarget( afx, d.c, "chest" ) return d endmethod static method create takes unit c, real s, real mh, real md, string fx returns Data local Data d = Data.coreCreate( c, fx ) local real a = GetUnitFacing( c ) * bj_DEGTORAD set d.s = s set d.mh = 4 * mh / md // also doesn't work with the given mh, set d.md = md set d.cos = Cos( a ) set d.sin = Sin( a ) set d.ITWrd = 100. call d.Start( ) return d endmethod static method createMissile takes unit c, real tx, real ty, real s, real mh, real md, real collision returns Data local Data d = Data.coreCreate( c, "" ) local real a = Atan2( ty - GetUnitY( c ), tx - GetUnitX( c ) ) set d.s = s set d.mh = mh set d.md = md set d.rd = collision set d.cos = Cos( a ) set d.sin = Sin( a ) call d.Start( ) return d endmethod method onDestroy takes nothing returns nothing set total = total - 1 set dat[.id] = dat[total] set dat[.id].id = .id call SetUnitFlyHeight( .c, GetUnitDefaultFlyHeight( .c ), 0. ) call DestroyEffect( .ef ) if .rd <= 0. then call KillUnit( .c ) endif endmethod endstruct function MissileThrow takes unit c, real tx, real ty, real s, real mh, real md, real collision returns nothing call Data.createMissile( c, tx, ty, s, mh, md, collision ) endfunction endlibrary |
