Moving a unit in a circle

dudeim

New Member
Reaction score
22
Hey,

I'm trying to move a projectile (unit) in a circle but as i'm really bad with math and have no idea how I would even do this:p
I've seen some spells that use this but I couldn´t really figure out how it works and I want to learn how to use it myself not just C&P.

Can anyone help me on this?

Thanks
 

Sevion

The DIY Ninja
Reaction score
413
You could use Sin/Cos:

JASS:
scope spin initializer init
    globals
        private unit theUnit = null
        private constant real RADIUS = 250
        private constant real SPEED = 10 * bj_DEGTORAD
        private real ang = 0
    endglobals

    // This is the function that does the actual spinning
    private function doSpin takes nothing returns nothing
        // This is the part you want
        call SetUnitX(theUnit, GetUnitX(theUnit) + RADIUS * Cos(ang))
        call SetUnitY(theUnit, GetUnitY(theUnit) + RADIUS * Sin(ang))
        set ang = ang + SPEED
    endfunction

    private function init takes nothing returns nothing
        set theUnit = CreateUnit('ewsp', Player(0), RADIUS, 0, 0)
        call TimerStart(CreateTimer(), 0.0325, true, function doSpin)
    endfunction
endscope
 

Nestharus

o-o
Reaction score
84
Sev just showed the crappy way. The best way is by using the parametric equation for a whirpool type vector field. If you want constant speeds regardless of circle size, you'd want to use unit vectors by dividing by the absolute value (excluding 0 ofc).

You can also shift it around the map and change the radius and speed =P.

JASS:

scope spin initializer init
    globals
        private unit theUnit = null
    endglobals
    private function doSpin takes nothing returns nothing
        local real x=GetWidgetX(theUnit)
        local real y=GetWidgetY(theUnit)
        call SetUnitX(theUnit, x-y)
        call SetUnitY(theUnit, y+x)
    endfunction

    private function init takes nothing returns nothing
        set theUnit = CreateUnit('ewsp', Player(0), 0, 0, 0)
        call TimerStart(CreateTimer(), 0.03250000, true, function doSpin)
    endfunction
endscope
 

dudeim

New Member
Reaction score
22
Pff too tired to figure it all out right know I'll see it in the morning thanks for responding;)
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
How to think: Take the unit you want and a circle, remember circle's characteristics, and think of it moving on that circle like a short movie.
Take now the circles characteristics, what does it change, what does remain same ?
If answered the above questions you know know how to solve it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top