A Flash Developer Resource Site

Thread: making an object move in a circle

1. making an object move in a circle

hello
does anybody know how to make an object moving in a smooth circle?

I guess its not much of code but I just dont get there...

2. Sin and Cosine are your friends.

Basic circlular motion is given by the following formula:

cx,cy are the center of the circle and

As time goes from 0 to 2*PI (or multiples thereof), the x,y values will describe a complete circle.

Here is an example of using this formula. Attach this script to the object you wish to move.

Code:
```onClipEvent(load)
{
cx = Stage.width/2; // coords of center of circle (center of screen, in this case)
cy = Stage.height/2;

speed = 6; // speed of travel (seconds to make a complete circuit)
speedScale = (0.001*2*Math.PI)/speed;
}

onClipEvent(enterFrame)
{
var angle = getTimer()*speedScale;
}```
For an example of using sin and cosine to move text in a curvy pattern, see this thread:

text effect

3. hey jim,

do you have or know where i can find motion for elipses?

thanks,
brint

4. Hi,

you could scale the values of the sin and cos parts in the equations,

eg,

this._x = cx + 1.5 * Math.sin(angle)*rad;

here the clip would move further from the origin in the x direction than it does in the y direction

5. To get an ellipse, use separate radii for the horizontal and vertical coordinates.

.
.
.

- Jim

Edit: Whoops, crossposted with catbert. We're basically saying the same thing. Catbert is defining radA in terms of it's relationship to radB (aspect ratio = 1.5).

6. thanks guys that was 2 ez

7. hey thanks a million for the help. it really IS kinda easy

8. trying to put my icons in a circle

Hi,

I'm trying to put my icons in a circle. I'm using this code for a straight line.

Code:
```var spacing = 10 + count * 113.15 ;//left spacing +i*item._width

var t = home.menuHolder.attachMovie("item","item"+count, count+16, {_x:spacing, _y:0, _xscale:75, _yscale:75, _alpha:0});```

Is there away to get this into a circle?

AS3 Circular Movement

10. very cool!

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap