# [Spell]Units moving in a circle

Status
Not open for further replies.

#### SSJ7107

Level 5
How can I make a unit move in a circle around a caster or a certain point?

Level 28
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.

#### Tasyen

Level 37
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.

#### SSJ7107

Level 5
Thanks, really helpful. Can I ask if there is any value for RotationSpeed?

#### Tasyen

Level 37
RotationSpeed is an angle (real), currently it is meant to hold an anglechange in seconds.
Means if you put there 60 your Missle rotate 60° anticlockwise a second.
for clockwise rotation you need to use negative rotationspeed

#### SSJ7107

Level 5
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.

#### SSJ7107

Level 5
Ok, nevermind. I have fixed it thanks a lot

Status
Not open for further replies.

Replies
10
Views
1K
Replies
4
Views
5K
Replies
4
Views
670
Replies
7
Views
934
Replies
8
Views
719