• 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.

[Spell] Units moving in a circle

Status
Not open for further replies.
Pseudocode:

Code:
function MoveUnitAroundCaster(unit circler, unit circlee)
    int i = 0
    while i >= 0
        circler.SetX(circlee.getX() + 250*Cos(i*1/50*PI))
        circler.SetY(circlee.getY() + 250*Sin(i*1/50*PI))
        if i += 1 < 2147483647
            i++
        wait(1/50)

The principle is that we have a certain interval such as 0.04 or 0.03, (I used 0.02 or 1/50.), and that we move the circler around the circlee via SetUnitX and SetUnitY, basing the coordinates off of the circlee's coordinates. We allow the passage of that time interval to execute the moving all over again.

Do note that for all intents and purposes, a timer should be used for periodic intervals of such shortness instead of a Wait - real someDur seconds GUI function because of desynchronization.
 
A Simple Version supporting 1 Rotating Unit showing the concept in GUI.

  • Simple Rotate for 1 Unit
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set CurrentAngle = (CurrentAngle + (RotationSpeed x 0.05))
      • Set Loc = (Position of Center)
      • Set Loc2 = (Loc offset by CurrentDistance towards CurrentAngle degrees)
      • Custom script: call RemoveLocation(udg_Loc)
      • Unit - Move RotatingUnit instantly to Loc2
      • Custom script: call RemoveLocation(udg_Loc2)
To support more then 1 Unit you need some kind of indexing or use an hashtable.

Another way would be to use Spell System which takes away the burden to calc index and the intervale.
 
Level 5
Joined
Oct 16, 2015
Messages
132
Ok, I've tries it but there is a problem. It rotates in a circle form, but there is like an error that it overlaps on the center and moves instantly to the opposite of the point it must be and I don't know why. It shows like 2 units rotating around the point.

It is kinds hard to explain because I suck at english, forgive me.
 
Status
Not open for further replies.
Top