• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Elipse Movement

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi. I'm working on some kind of "swarm" effect attack, making flyes attack targets but not moving directly towards them, but making them follow an eliptic trayectory from the main bug to the target, attack it whiel moving (at the middle of the trayectory) then go back to the bug mother.

I know how to do the SetUnitX and SetUnitY and stuff but i don't know how to achieve the right "trayectory" to follow an eliptic shape. I would love to have some function like "ElipticAttack(Attacker, Target)" that handles everything.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Think of it as a space mothership that sends smaller ships to attack enemies. The ships come out from the source, attack the target following the lines, then come back to the source, but not following a straight trayectory, but an eliptic one.

Note: Sorry if I'm not saying it correctly, I'm not english native.
 

Attachments

  • Imagen1.png
    Imagen1.png
    34.2 KB · Views: 127
Level 20
Joined
Jul 14, 2011
Messages
3,213
I don't get it I hate feelling (being) noob -.-

EDIT: Finnally managed to find formulas around to help me with this, but the Parabola isn't "perfect", i mean, the Unit doesn't goes exactly above the points (but a bir further) and the unit doesn't moves from one border to the other one, only passes over both on any point of the elipse
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
@Maker: I tried, but got confused with it; didn't know how to translate that to jass.

@Ceday: Shouldn't matter. I mean, i know that moving the units (Target and Source) will mess a bit with the elipse exactitude, but it's enought for me.

I've tried several stuff understanding none of them :( Finnally found one that works BUT Only one the Y or X axis. I'm not sure how to fix it so it always passes over targets on the narrow part of the Elipse.

Just test the map as it is and you'll see the Wisp moves correctly untill you move the units outside the Y axis.

JASS:
// a = Width
// b = Tall
// w = Angle
// t = Some constant that ingreases to move the unit.
function ParametricX takes real t, real a, real b, real w returns real
    return a * Cos(t) * Cos(w) - b * Sin(t) * Sin(w)
endfunction

function ParametricY takes real t, real a, real b, real w returns real
    return a * Cos(t) * Sin(w) + b * Sin(t) * Cos(w)
endfunction

function InterceptorAttack takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local integer id = GetHandleId(T)
    local unit Interceptor = LoadUnitHandle(CarrierHash, id, 0)
    local unit Source = LoadUnitHandle(CarrierHash, id, 1)
    local unit Target = LoadUnitHandle(CarrierHash, id, 2)
    local real t = LoadReal(CarrierHash, id, 3) + 0.03 * 0.5 * (2*bj_PI)
    local real Sx = GetUnitX(Source)
    local real Sy = GetUnitY(Source)
    local real Tx = GetUnitX(Target)
    local real Ty = GetUnitY(Target)
    local real Dx = GetUnitX(Interceptor)
    local real Dy = GetUnitY(Interceptor)
    local real Cx = (Sx + Tx) / 2 // Center X
    local real Cy = (Sy + Ty) / 2 // Center Y
    local real DistX = Tx - Sx
    local real DistY = Ty - Sy
    local real Width = SquareRoot(DistX * DistX + DistY * DistY) / 2 // Distance Between Source and Target
    local real Tall = Width / 2
    local real Angle = Atan2(DistX, DistY) * bj_DEGTORAD
    local real z
    local real xoff 
    local real yoff
    
    set xoff = ParametricX(t, Tall, Width, Angle) + Cx
    set yoff = ParametricY(t, Tall, Width, Angle) + Cy
    
    call SaveReal(CarrierHash, id, 3, t)
    
    call SetUnitX(Interceptor, xoff)
    call SetUnitY(Interceptor, yoff)
    
    set T = null
    set Interceptor = null
    set Source = null
    set Target = null
endfunction

Found it here: http://www.thehelper.net/threads/elliptical-orbits.136285/
 

Attachments

  • Carriers.w3x
    21.3 KB · Views: 60
Level 14
Joined
Jun 27, 2008
Messages
1,325
Life would be easier if your carrier is static, but I think it is not :(

Doesnt matter, you can just add the carriers movement to the flies. (Just add the vectorized distance of the carrier from its initial position to the flies position in every timestep).
This isnt 100% correct compared to the underlying physical movement, but its very close.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I can't believe it. I finally achieved it. I just had to turn this
local real Angle = Atan2(DistX, DistY) * bj_DEGTORAD
into this
local real Angle = Atan2(DistY, DistX)


JASS:
// and this
    set xoff = ParametricX(t, Tall, Width, Angle) + Cx
    set yoff = ParametricY(t, Tall, Width, Angle) + Cy


// into this

    set xoff = ParametricX(t, Width, Tall, Angle) + Cx
    set yoff = ParametricY(t, Width, Tall, Angle) + Cy
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I improved it in general :) Any further suggestion?

JASS:
function InterceptorAttack takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local integer id = GetHandleId(T)
    local unit Interceptor = LoadUnitHandle(CarrierHash, id, 0)
    local unit Source = LoadUnitHandle(CarrierHash, id, 1)
    local unit Target = LoadUnitHandle(CarrierHash, id, 2)
    local real t = LoadReal(CarrierHash, id, 3) + 0.075
    local real Sx = GetUnitX(Source)
    local real Sy = GetUnitY(Source)
    local real Tx = GetUnitX(Target)
    local real Ty = GetUnitY(Target)
    local real Dx = GetUnitX(Interceptor)
    local real Dy = GetUnitY(Interceptor)
    local real Cx = (Sx + Tx) / 2 // Center X
    local real Cy = (Sy + Ty) / 2 // Center Y
    local real DistX = Sx-Tx
    local real DistY = Sy-Ty
    local real Width = SquareRoot(DistX * DistX + DistY * DistY) / 2 // Distance Between Source and Target
    local real Tall = Width / 3
    local real Angle = Atan2(DistY, DistX)
    local real Cos1 = Cos(t)
    local real Sin1 = Sin(t)
    local real Cos2 = Cos(Angle)
    local real Sin2 = Sin(Angle)
    local real R1 = Width*Cos1
    local real R2 = Tall*Sin1
    local real xoff = (R1 * Cos2 - R2 * Sin2) + Cx
    local real yoff = (R1 * Sin2 + R2 * Cos2) + Cy
    
    call SaveReal(CarrierHash, id, 3, t)
    
    call SetUnitX(Interceptor, xoff)
    call SetUnitY(Interceptor, yoff)
    
    set T = null
    set Interceptor = null
    set Source = null
    set Target = null
endfunction
 
Last edited:
Status
Not open for further replies.
Top