- Joined
- Jul 10, 2007
- Messages
- 6,306
I made this while working on a system for testing purposes and found it fun to watch = ).
You need the latest vJASS to run this. You can just paste it into a random map and hit save/test and it'll run : P
And here is 3D targeting methinks. If anyone wants to check over my math, go for it : D. I winged it, lol (Never done 3D vectors before, just used mah logic)
Next I gotta do magnetism, elasticity, friction, precise collision, and gravity i think? : O
You need the latest vJASS to run this. You can just paste it into a random map and hit save/test and it'll run : P
JASS:
//! external ObjectMerger w3a Amrf PFLY ansf "(PFLY)" aart "" arac 0
struct Tester extends array
//START_X and START_Y determined by map
private static constant real START_PITCH = 225
private static constant real START_YAW = 45
private static constant real START_Z = 500
private static constant integer PLATFORM_FLY = 'PFLY'
private static constant real INTERVAL = .03125
private static real fieldOffset
private static unit u
private static real x
private static real y
private static real z
private static real yaw //left right
private static real pitch //90 up, 270 down
private static real yawRad
private static real pitchRad
private static real velocity
private static real translationX
private static real translationY
private static real translationZ
private static real maxX
private static real maxY
private static real minX
private static real minY
private static method run takes nothing returns nothing
if (x >= maxX or x <= minX) then
set translationX = translationX*-1
set translationZ = translationZ * -1
endif
if (y >= maxY or y <= minY) then
set translationY = translationY * -1
set translationZ = translationZ * -1
endif
if (z <= 0 or z >= 1000) then
set translationZ = translationZ * -1
endif
set x = x + translationX
set y = y + translationY
set z = z + translationZ
call SetUnitX(u, x)
call SetUnitY(u, y)
call SetUnitFlyHeight(u, z, z/INTERVAL)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, z+fieldOffset, 0)
call SetCameraPosition(x, y+z/2)
endmethod
private static method onInit takes nothing returns nothing
local fogmodifier fog = CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false)
set maxX = GetRectMaxX(bj_mapInitialPlayableArea)
set maxY = GetRectMaxY(bj_mapInitialPlayableArea)
set minX = GetRectMinX(bj_mapInitialPlayableArea)
set minY = GetRectMinY(bj_mapInitialPlayableArea)
set fieldOffset = GetCameraField(CAMERA_FIELD_TARGET_DISTANCE)
set x = (RAbsBJ(maxX)-RAbsBJ(minX))/2
set y = (RAbsBJ(maxY)-RAbsBJ(minY))/2
set z = START_Z
set pitch = START_PITCH
set yaw = START_YAW+90
call FogModifierStart(fog)
call TimerStart(CreateTimer(), INTERVAL, true, function thistype.run)
set u = CreateUnit(Player(0), 'ewsp', x, y, yaw)
call SelectUnit(u, true)
call SetPlayerAbilityAvailable(Player(0), PLATFORM_FLY, false)
call UnitAddAbility(u, PLATFORM_FLY)
call UnitMakeAbilityPermanent(u, true, PLATFORM_FLY)
call SetUnitFlyHeight(u, z, z/INTERVAL)
set pitchRad = pitch*bj_DEGTORAD
set yawRad = yaw*bj_DEGTORAD
set velocity = 100*10
set translationX = INTERVAL*velocity*Sin(yawRad)*Cos(pitchRad)
set translationY = INTERVAL*velocity*Cos(yawRad)*Cos(pitchRad)
set translationZ = INTERVAL*velocity*Sin(pitchRad)
endmethod
endstruct
And here is 3D targeting methinks. If anyone wants to check over my math, go for it : D. I winged it, lol (Never done 3D vectors before, just used mah logic)
JASS:
set yawRad = Atan2(targetY - yK, targetX - xK)
set yawK = yawRad*bj_RADTODEG
set pitchX = SquareRoot(Pow(targetX-xK, 2)+Pow(targetY-yK, 2))
set pitchY = targetZ-zK
set pitchRad = Atan2(pitchY, pitchX)
set pitchK = pitchRad*bj_RADTODEG
set translationX = MOVE_INTERVAL*speedK*Sin(yawRad)*Cos(pitchRad)
set translationY = MOVE_INTERVAL*speedK*Cos(yawRad)*Cos(pitchRad)
set translationZ = MOVE_INTERVAL*speedK*Sin(pitchRad)
Next I gotta do magnetism, elasticity, friction, precise collision, and gravity i think? : O